I am strugglig doing a save button in C# Windows Form Application where I have a GridView and I want to save all modification I do in GridView Table(I connected it to sql). This is the data source for my database DataTable dtCustomers = new DataTable();
I did this so far and got stucked.
private void SaveButton_Click(object sender, EventArgs e)
{
string connectionString = Properties.Settings.Default.dbConnectionString;
SqlConnection con = new SqlConnection(connectionString);
using (con)
{
SqlCommand cmd = con.CreateCommand();
using (cmd)
{
cmd.CommandText = @"UPDATE CUSTOMERS SET " +
"CustomerId = @CustomerId, " +
"FirstName = @FirstName, " +
"LastName = @LastName, " +
"Email = @Email, " +
"Height = @Height, " +
"DateOfBirth = @DateOfBirth ";
cmd.Parameters.Add("@CustomerId", SqlDbType.Int, 5, "StudentID");
cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 50, "FirstName");
cmd.Parameters.Add("@LastName", SqlDbType.VarChar, 50, "LastName");
cmd.Parameters.Add("@Email", SqlDbType.VarChar, 1, "Email");
cmd.Parameters.Add("@Height", SqlDbType.Int, 50, "Height");
cmd.Parameters.Add("@DateOfBirth", SqlDbType.Date, 10, "DateOfBith");
cmd.Connection = con;
using (SqlDataAdapter da = new SqlDataAdapter())
{
da.UpdateCommand = cmd;
// da.Update();
}
}
}
Thank you for any suggestion!