ADO connectivity in windows C# .Net and also trying to insert the data from text box to database. RRS feed

  • Question

  • Hi Gays

    I am beginner if ADO .Net and trying to insert the data in database from text box. For that I had establish the connection n now I want to insert the data from text box. Please help me.


    private void btnSave_Click(object sender, EventArgs e)
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = "Data Source = WEBSOFTEX-3; Initial Catalog=Amitb; User Id=Sa; Password=123";
                    string quary = "insert into ADO values(@Emp_Id, Emp_Name)";
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = quary;
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@Emp_Id", txtID.Text.ToString());
                    cmd.Parameters.AddWithValue("@Emp_Name", txtName.Text.ToString());
                    cmd.Connection = con;
                catch (Exception ed)


    When I execute this code it gave error. Please help me, so that I could learn ADO .Net.




    • Moved by VMazurModerator Wednesday, February 4, 2009 10:53 AM (Moved from ADO.NET Data Services to ADO.NET Data Providers)
    Wednesday, January 28, 2009 3:14 PM

All replies

  • No no we dont tell you the answer, you have to pay for this kind of support
    --------------joking aside

    Hi Amitbaranwal

    You have posted this on the wrong forum.

    Try posting on the Ado.Net Data Providers Forum

    Daniel Portella Blogger from hell
    if this reply has answer your question please mark as the answer.

    Daniel Portella - - This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, January 28, 2009 3:40 PM
  • Hi Amit,

    you might only need to make a small change:

    string quary = "insert into ADO values(@Emp_Id, @Emp_Name)";

    This should work if the table contains only the two columns and the values in both columns can be edited manually (e.g. the ID field is not an Identity field). You have to add a field list if the table contains more columns. The additional columns must allow null values or are filled automatically (default value, identity value). Adding the field list would results in a statement like this:

    string quary = "insert into ADO(EMPID, EMPNAME) values(@Emp_Id, @Emp_Name)";

    Please provide the exceptions details if this doesn't solve the problem!

    Hope this helps


    Friday, January 30, 2009 11:30 AM