C# Add/Update records from DataGridView to SQL database. ADO.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gaya12
    New Member
    • Nov 2007
    • 5

    #1

    C# Add/Update records from DataGridView to SQL database. ADO.NET

    I have a table called Student in a SQL databse.. I have to create a simple windows application in C# to Retrieve that table for the following functions..
    1.Add Data
    2.Update Data
    3.View Data

    For this Im using Datagridview and ADO.NET.. Im able to view the data.. but I dont know how to Add and update data...
    When I add/update the changes should be done in the SQL database.. How can I do that?
    Any help?

    This is the method Im using for View the data

    Code:
    public DataSet Retrieve()
            {
                SqlConnection conn = new
                    SqlConnection("Server=White\\SQLEXPRESS;Integrated Security=SSPI;database=Student);
                SqlDataAdapter cmd = new SqlDataAdapter("select * from students", conn);
                DataSet result = new DataSet();
                cmd.Fill(result, "students");
                return result;
            }
    
    
    private void Form1_Load(object sender, EventArgs e)
            {
                System.Data.DataSet DS = new System.Data.DataSet();
                StuData.Class1 ostu = new StuData.Class1();
                DS = ostu.Retrieve();
                dataGridView1.DataSource = DS.Tables[0];
            }
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Please search the site for examples. HTH.

    Comment

    Working...