我正在尝试使用C#
更新一个故事,但是,我无法做到这一点。我想在GridView中显示所有数据,包括更新的行。任何帮助表示赞赏。
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;
}
我收到此错误:
System.Data.SqlClient.SqlException HResult = 0x80131904 Message =','附近的语法不正确。 Source = .Net SqlClient数据提供程序 StackTrace:位于 System.Data.SqlClient.SqlConnection.OnError(SqlException异常, 布尔值breakConnection,Action1 wrapCloseInAction)位于 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException 异常,布尔值breakConnection,Action1 wrapCloseInAction)位于 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject