ADO.NET具有支持连接模式的DataReader。所有其他都断开连接。
DataReader是连接的体系结构,因为它保持连接打开,直到获取所有记录
如果要插入ADO.NET,则应执行以下步骤:
private void btnadd_Click(object sender, EventArgs e)
{
try
{
//create object of Connection Class..................
sqlConnection con = new sqlConnection();
// Set Connection String property of Connection object..................
con.ConnectionString = "Data Source=KUSH-PC;Initial Catalog=test;Integrated Security=True";
// Open Connection..................
con.open();
//Create object of Command Class................
sqlCommand cmd = new sqlCommand();
//set Connection Property of Command object.............
cmd.Connection = con;
//Set Command type of command object
//1.StoredProcedure
//2.TableDirect
//3.Text (By Default)
cmd.CommandType = CommandType.Text;
//Set Command text Property of command object.........
cmd.CommandText = "Insert into Registration (Username, password) values ('@user','@pass')";
//Assign values as `parameter`. It avoids `sql Injection`
cmd.Parameters.AddWithValue("user", Text@R_457_2419@1.text);
cmd.Parameters.AddWithValue("pass", Text@R_457_2419@2.text);
Execute command by calling following method................
1.ExecuteNonQuery()
This is used for insert,delete,update command...........
2.ExecuteScalar()
This returns a single value .........(used only for select command)
3.ExecuteReader()
Return one or more than one record.
cmd.ExecuteNonQuery();
con.Close();
Message@R_457_2419@.Show("Data Saved");
}
catch (Exception ex)
{
Message@R_457_2419@.Show(ex.Message);
con.Close();
}
}