I want to make a connection and fetching data from MS SQL Server and display inside the textbox. RRS feed

  • Question

  • Hello Guys


    I am beginner in ADO .Net n trying to retrieve the data from database n also want to doing some DML activity. I had make make a connection n now I want to retrieve the data inside the text box (or you can say that what ever value will come display inside the text box). I am also sending the code but its incomplete. Please help me so that I could learn this part.

       private void Form1_Load(object sender, EventArgs e)
                    SqlConnection con = new SqlConnection();
                    con.ConnectionString = "Data Source = WEBSOFTEX-3; Initial Catalog=Amitb; User Id=Sa; Password=123";
                    string quary = "Select * from ADO";
                    SqlDataAdapter adapter = new SqlDataAdapter(quary, con);
                    SqlCommandBuilder cmdbuikder = new SqlCommandBuilder(adapter);
                    DataSet ds = new DataSet("ADO");
                    adapter.Fill(ds, "ADO");
                    DataRow row = ds.Tables["ADO"].Rows;
                    row["Emp_ID"] = txtID.Text;
                    row["Emp_Name"] = txtName.Text;

                   // SqlCommand cmd = new SqlCommand(quary, con);
                   /* SqlDataReader read = cmd.ExecuteReader();

                    while (read.Read())
                        Console.WriteLine(read[0] + "" + read[1]);
                catch (Exception ed)
                    MessageBox.Show("Error in Saving\n" + ed.ToString(), "Error");

    Please help me.



    Monday, January 26, 2009 1:11 PM

All replies

  • It looks like you have a mixture of DataReader and DataSet code here. Which would you prefer to use, a DataReader or a DataSet/DataTable?
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Tuesday, January 27, 2009 2:32 PM