总报错:未将对象引用设置到对象的实例。
代码如下:
1 Dim defmm As String = "1234"
2 Dim xkdh As String = Microsoft.VisualBasic.Left(ComboBox1.Text, 2)
3 da.InsertCommand.CommandText = "insert into yh (yh_id,yh_mm,yh_xm,yh_xk) values ('" & txtid2.Text & " ' ,'" & defmm & " ','" & txtxm.Text & "','" & xkdh & "' ) "
4 da.InsertCommand.Parameters.Add("@yh_id", SqlDbType.VarChar, 4)
5 da.InsertCommand.Parameters.Add("@yh_mm", SqlDbType.VarChar, 8)
6 da.InsertCommand.Parameters.Add("@yh_xm", SqlDbType.VarChar, 20)
7 da.InsertCommand.Parameters.Add("@yh_xk", SqlDbType.VarChar, 2)
8 da.Update(ds, "yh")
执行到第3行时错误,总提示xkdh未将对象引用这只到对象实例,请高手帮帮忙吧
[解决办法]
看 xkdh 是什么值
[解决办法]
xkdh在第2行已经赋值,第3行运行应没有问题了。先把第3行中xkdh去掉看看,是否还出现问题,如没问题,再把第2行分成两行(第一行定义,第二行赋值)试试。