hi friends
i am new in web site devlopment . i got error in data updation coding . cauld u help me .
protected void update_Click(object sender, EventArgs e){
SqlDataReader rdr = null; string myConnectString = "Data Source=NBAP25169578480;Initial Catalog=employee;Integrated Security=True"; SqlConnection con = new SqlConnection(myConnectString);con.Open ();
SqlCommand cmd = new SqlCommand("update emp set where userid ="+TextBox3.Text+"",con );rdr =
new SqlDataReader (); if(rdr.Read ()){
cmd.Parameters.AddWithValue(
"@password", TextBox1.Text);cmd.Parameters.AddWithValue(
"@userid", TextBox2.Text);}
rdr = cmd.ExecuteReader();
// cmd.Connection = con;cmd.Connection.Open();
// cmd.ExecuteNonQuery();cmd.Dispose();
con.Close();
}
thanks
regards
bhawna
bhawna jainPosted Jul 15, 2008, 12:01 PM
thanks satish
now it is working .
regards
bhawna
Satish KathiPosted Jul 15, 2008, 10:07 AM
protected void update_Click(object sender, EventArgs e)
{
string connectionString = “your connection string”
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand myCommand = new SqlCommand("update employee set ename = 'Some Name' where emp_id = " + TextBox1.Text, conn);
conn.Open();
myCommand.ExecuteNonQuery();
conn.Close();
}
The update SQL in your code is wrong.
You can’t use constructor to create an object of SQLDataReader.
And when you are using DML commands you have to use method ExecuteNonQuery.