how to insert row in SQL database in ADO.Net Connection oriented mode

ado.net, sql

Solution

ADO.NET has DataReader which supports Connected mode. All else are disconnected.

DataReader is connected architecture since it keeps conneection open untill all records are fetched

If you want to insert in ADO.NET then you should perform the following steps:

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", TextBox1.text);
cmd.Parameters.AddWithValue("pass", TextBox2.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();


  MessageBox.Show("Data Saved");          
  }
     catch (Exception ex)
     {
            MessageBox.Show(ex.Message);
            con.Close();
     }


    }

Problem

I have a database in which a table has name `Registration` which is used to register the user. It has only two column one is `Username` and one is `password`. A page named `Register.aspx` is used for registering the member which have two textbox one is for taking `Username(textbox1)` and one is for taking `password(textbox2)` and one button for insert these value in database. The Main problem is that we cannot write statement like this : ``` Insert into Registration (Username, password) values ('TextBox1.text','TextBox2.text') ``` I am using ADO.net Connection oriented mode, I googled but I didn't find any way to insert row in SQL database in connected mode. Please provide me a idea for inserting this row?

Original source