0

我正在尝试确认我能够写入数据库。我基本上在做的是说

Insert into locationChangeTable (Col1,Col2,Col3) Values (Val1,Val2,Val3)

然后尝试使用这些值来选择我刚刚向上推回的记录(没有主键)

select (Col1,Col2,Col3) from locationChangeTable 
      where (Col1=Val1) AND (Col2=Val2) AND (Col3=Val3) 

有时它会找到我的记录并返回它,但大多数时候我没有从选择中得到任何结果。我在这里提供了我的代码摘录

有谁知道为什么它没有像我期望的那样找到它们?或者对其他方式有任何建议来确认我的插入语句在 vb.net 中是成功的

4

1 回答 1

1

这样的事情是否不能满足您的要求,而不是重新查询数据库:

Dim command1 New SqlCommand("Insert into locationChangeTable (Col1,Col2,Col3) Values ('Val','Val2','Val3')", connection1)

connection1.Open()
returnValue = command1.ExecuteNonQuery()
writer.WriteLine("Rows to be affected by command1: {0}", returnValue)
connection1.Close()

这将返回受命令影响的行数。样品取自这里

和选择

Dim command2 New SqlCommand("Select into locationChangeTable (Col1,Col2,Col3) Values ('Val','Val2','Val3')", connection1)
connection1.Open()
returnValue = command1.ExecuteNonQuery()
connection1.Close()
于 2014-04-16T15:46:05.240 回答