使用C#向SQL Server插入数据时,报错Object reference not set to an instance of an object

代码如下:
连续插入很多条数据,其中就会突然报两次Object reference not set to an instance of an object.

DbConnection cnn;(这里是提前new过的,一直保持的连接状态)
string sqlString = "INSERT INTO [dbo].[Events] VALUES (N'{XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXXXX}',1000,N"HAHA');
DbCommand cmd = new SqlCommand(queryString,cnn as SqlConnction);

try
{
cmd.Transaction = cnn.BeginTransaction();
cmd.CommandText = sqlString;
cmd.ExcuteNonQuery();
cmd.Transation.Commit();
}
catch(Exception e)
{
....
}

查看全部
Bravery_mystyle
Bravery_mystyle
2020/03/20 17:18
  • c#
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复