SqlConnection conn = new SqlConnection("server=myserver;database=allexample;Integrated Security=SSPI;");
SqlCommand cmd;
SqlDataAdapter da;
SqlDataReader dr;
DataSet ds = new DataSet();
ON Page Load
con.Open();
da =new SqlDataAdapter("select * from New_user",con);
DataSet ds = new DataSet();
da.Fill(ds,"New_user");
datagrid1.DataSource=ds;
datagrid1.DataBind();
con.Close();
OR (SELECT)
cmd = new SqlCommand("select * from user_info where userid=@userid", conn);
int myvalue = Convert.ToInt16(GridView1.SelectedRow);
cmd.Parameters.Add("userid",GridView1.SelectedValue);
dr = cmd.ExecuteReader();
dr.Read();
while(dr.Read())
{
assign values to diffrent control.
}
dr.Close();
conn.Close();
OR(INSERT)
cmd = new SqlCommand("insert into New_user values('" +txtfname.Text + "','" + txtlastname.Text + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
OR(UPDATE)
cmd = new SqlCommand("update user_info set firstname=@firstname,lastname=@lastname where userid=@userid", conn);
cmd.Parameters.Add("userid", txtuid.Text);
cmd.Parameters.Add("firstname",txtfname.Text);
cmd.Parameters.Add("lastname",txtlname.Text);
statuslabel.Text = "Your record updated successfully...";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Wednesday, February 3, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment