Try another command:
cmd.CommandText = @"UPDATE CUSTOMERS SET
FirstName = @FirstName,
LastName = @LastName,
Email = @Email,
Height = @Height,
DateOfBirth = @DateOfBirth
WHERE CustomerId = @CustomerId";
What happens in this case?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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 = @tiedtlaw 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("@tiedtlaw 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!
Try another command:
cmd.CommandText = @"UPDATE CUSTOMERS SET
FirstName = @FirstName,
LastName = @LastName,
Email = @Email,
Height = @Height,
DateOfBirth = @DateOfBirth
WHERE CustomerId = @CustomerId";
What happens in this case?
HiCriAticus-8329,
>>I did this so far and got stucked.
What specific problem did you encounter? Please explain in detail.
And refer to the following code(I only listed a few fields):
cmd.CommandText = @"update CUSTOMERS set CustomerId= @CustomerId, FirstName= @FirstName,LastName = @LastName where CustomerId= = @oldCustomerId";
cmd.Parameters.Add("@CustomerId= ", SqlDbType.Int, 5, "StudentID");
cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 50, "FirstName");
cmd.Parameters.Add("@LastName", SqlDbType.VarChar, 50, "LastName");
SqlParameter parameter = cmd.Parameters.Add("@oldCustomerId", SqlDbType.Int, 5, "StudentID");
More details I suggest you follow this document.
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.htmlElba-3401