Hi everyone,
I have textbox = numberic value(eNTER numberic)
submit = button
After enter values in the text box.. submit the value and its should update in the sql table. [table already created in sql)
I having problem with submitting value and saving part into sql.
Any sample please..
Thanks everyone
Loading
Jignesh TrivediPosted Feb 28, 2012, 4:35 AM
Try..
Client Side
Server side.
var k = Convert.ToInt32(Request.Params["txt1"]);
ORvar k = Convert.ToInt32(txt1.Text);
SqlConnection con = new SqlConnection(strConnString);
con.Open();
com = new SqlCommand("insert into employee (columnName) values('" + txt1.Text + "')", con);
com.ExecuteNonQuery();
com.Dispose();
con.Close();
hope this help.
Satyapriya NayakPosted Feb 27, 2012, 9:31 PM
com = new SqlCommand("Update into Sparepartslist values(@Current Quantity)", dbCon);
Your update command is not correct
See the below code and do it accordingly.
com=new SqlCommand("update Sparepartslist set Current Quantity=@Current Quantity where Category=@Category", dbCon);
com.Parameters.AddWithValue("@Category", txtCategory.Text);
com.Parameters.AddWithValue("@Current Quantity", txtQuantity.Text);
com.ExecuteNonQuery();
Thanks
shshvaPosted Feb 27, 2012, 8:55 PM
Satyapriya NayakPosted Feb 27, 2012, 5:51 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Insert_data_confirmation.WebForm1" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace only numeric values
{
public partial class WebForm1 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void btn_insert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
com = new SqlCommand("insert into employee1 values(@sal)", con);
com.Parameters.AddWithValue("@sal", txtsal.Text);
com.ExecuteNonQuery();
com.Dispose();
con.Close();
Response.Write("Records successfully inserted");
clear();
}
void clear()
{
txtsal.Text = "";
}
}
}
Thanks
If this post helps you mark it as answer