How to update a database/table using C# & show the changes instant in GridView?

0

I'm trying to update a tale with C#, but, I'm not able to to that. I want to show all the data in GridView including the updated rows as well. Any help much appreciated.

String connectionString = @"Data Source=11.71.38.9;Database=DB;User Id=admin;Password=12345";
DataTable dtbl = new DataTable();
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
    sqlCon.Open();
    SqlDataAdapter sqlData = new SqlDataAdapter("Update StudentsData set Name = ('" + txtBoxName.Text.ToString() + "', Address = '" + txtBoxAddress.Text.ToString() + "', Centre = '" + txtBoxCenter.Text.ToString() + "', City = '" + txtBoxCity.Text.ToString() + "', State = '" + txtBoxState.Text.ToString() + "' where ID = '" + txtBoxID.Text.ToString() + "')", sqlCon);
    sqlData.Fill(dtbl);
    CRUDDB.DataSource = dtbl;
}

I'm getting this error:

System.Data.SqlClient.SqlException HResult=0x80131904 Message=Incorrect syntax near ','. Source=.Net SqlClient Data Provider StackTrace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject

c#
winforms
gridview
datagridview
datagrid
asked on Stack Overflow Mar 12, 2019 by CyberSelf • edited Mar 12, 2019 by GuidoG

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0