i am using the following to insert value from text box into database ,, but when i execute my code , my database remains empty .. how can i slove my problem ??
//tell the compiler and database that we're using parameters (thus the @first, @last, @nick)
InsertData("insert into users(name,emailid,password,address,phone,city,state,pin)values('" + name + "','" + emailid + "','" + password + "','" + address + "','" + phone + "','" + city + "','" + state + "','"+pin+"')");
// Label1.Text = "Your Account Is SuccessFully Created";
Response.Write("inserted");
}
public int InsertData(string insertSQL)
{
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand(insertSQL, conn);
conn.Open();
int result = cmd.ExecuteNonQuery();
conn.Close();
puneet_invin...
Member
52 Points
96 Posts
storing textbox value in to database
Jun 12, 2012 07:12 PM|LINK
i am using the following to insert value from text box into database ,, but when i execute my code , my database remains empty .. how can i slove my problem ??
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
double phone = double.Parse(txtPhonno.Text);
string name = txtFirstname.Text + "_" + txtLastname.Text;
string address = txtAddress.Text;
string city = txtCity.Text;
string state = txtstate.Text;
double pin = double.Parse(txtPin.Text);
string emailid = txtMail.Text;
string password = txtPassword.Text;
// int TimeAdded = DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second;
//tell the compiler and database that we're using parameters (thus the @first, @last, @nick)
InsertData("insert into users(name,emailid,password,address,phone,city,state,pin)values('" + name + "','" + emailid + "','" + password + "','" + address + "','" + phone + "','" + city + "','" + state + "','"+pin+"')");
// Label1.Text = "Your Account Is SuccessFully Created";
Response.Write("inserted");
}
public int InsertData(string insertSQL)
{
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand(insertSQL, conn);
conn.Open();
int result = cmd.ExecuteNonQuery();
conn.Close();
return result;
}
MahadTECH
Star
8976 Points
1659 Posts
Re: storing textbox value in to database
Jun 12, 2012 07:30 PM|LINK
Watch this Video Tutorial it will tell u every thing..
http://www.youtube.com/watch?v=TFwRN8eGC4Y
your Code has error
try this corrected code.. and reply.
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString); string MyInsertCommand = @"INSERT INTO users (name,emailid,password,address,phone,city,state,ping) VALUES (@name,@emailid,@password,@address,@phone,@city,@state,@ping)"; SqlCommand cmd = new SqlCommand(MyInsertCommand, conn); cmd.Parameter.AddWithValue("@name", name); cmd.Parameter.AddWithValue("@emailid", emailid); cmd.Parameter.AddWithValue("@password", password); cmd.Parameter.AddWithValue("@address", address); cmd.Parameter.AddWithValue("@city", city); cmd.Parameter.AddWithValue("@state", state); cmd.Parameter.AddWithValue("@pin", pin); conn.Open(); cmd.ExecuteNonQuery();Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
puneet_invin...
Member
52 Points
96 Posts
Re: storing textbox value in to database
Jun 12, 2012 07:50 PM|LINK
thanks its working now