D
Deep
dear friend
I have written a code to update table using sqldataadapter. It is
not giving error but not updating table. Is it incomplete. Please tell
me how to do it?
protected void btnUpd_Click(object sender, EventArgs e)
{
string sqlUpd = "update empl2 set name=@name, age=@age,
salary=@salary, gender=@gender where empid=@empid";
string sqlData = "select * from empl2";
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmdselect = new SqlCommand(sqlData,con);
sda.SelectCommand = cmdselect;
DataSet ds = new DataSet();
sda.Fill(ds, "Empl");
SqlCommand cmdUpd = new SqlCommand();
cmdUpd.CommandText = sqlUpd;
cmdUpd.Parameters.Add("@name", SqlDbType.VarChar);
cmdUpd.Parameters["@name"].Value = txtName.Text;
cmdUpd.Parameters.Add("@age", SqlDbType.Int);
cmdUpd.Parameters["@age"].Value = txtAge.Text;
cmdUpd.Parameters.Add("@salary", SqlDbType.Float);
cmdUpd.Parameters["@salary"].Value = txtSalary.Text;
cmdUpd.Parameters.Add("@gender", SqlDbType.VarChar);
cmdUpd.Parameters["@gender"].Value =
ddlGender.SelectedItem.Value;
cmdUpd.Parameters.Add("@empid", SqlDbType.Int);
cmdUpd.Parameters["@empid"].Value = txtEmpId.Text;
sda.UpdateCommand = cmdUpd;
sda.Update(ds, "Empl");
//cmd.Connection = con;
//con.Open();
//cmd.ExecuteNonQuery();
//con.Close();
}
Thanks In Advance
I have written a code to update table using sqldataadapter. It is
not giving error but not updating table. Is it incomplete. Please tell
me how to do it?
protected void btnUpd_Click(object sender, EventArgs e)
{
string sqlUpd = "update empl2 set name=@name, age=@age,
salary=@salary, gender=@gender where empid=@empid";
string sqlData = "select * from empl2";
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmdselect = new SqlCommand(sqlData,con);
sda.SelectCommand = cmdselect;
DataSet ds = new DataSet();
sda.Fill(ds, "Empl");
SqlCommand cmdUpd = new SqlCommand();
cmdUpd.CommandText = sqlUpd;
cmdUpd.Parameters.Add("@name", SqlDbType.VarChar);
cmdUpd.Parameters["@name"].Value = txtName.Text;
cmdUpd.Parameters.Add("@age", SqlDbType.Int);
cmdUpd.Parameters["@age"].Value = txtAge.Text;
cmdUpd.Parameters.Add("@salary", SqlDbType.Float);
cmdUpd.Parameters["@salary"].Value = txtSalary.Text;
cmdUpd.Parameters.Add("@gender", SqlDbType.VarChar);
cmdUpd.Parameters["@gender"].Value =
ddlGender.SelectedItem.Value;
cmdUpd.Parameters.Add("@empid", SqlDbType.Int);
cmdUpd.Parameters["@empid"].Value = txtEmpId.Text;
sda.UpdateCommand = cmdUpd;
sda.Update(ds, "Empl");
//cmd.Connection = con;
//con.Open();
//cmd.ExecuteNonQuery();
//con.Close();
}
Thanks In Advance