Reputation: 1304
I'm trying to confirm that I was able to write to a database. What I'm basically doing is saying
Insert into locationChangeTable (Col1,Col2,Col3) Values (Val1,Val2,Val3)
and then trying to use those values to select the record I just pushed up back down (no primary key)
select (Col1,Col2,Col3) from locationChangeTable
where (Col1=Val1) AND (Col2=Val2) AND (Col3=Val3)
and sometimes It finds my record and returns it, but most of the time I don't get any results from the select. I provided excerpts of my code here
Does anyone know why it's not finding them like i would expect it to? or have any suggestions on other ways to confirm that my insert statement was sucessful in vb.net
Upvotes: 0
Views: 47
Reputation: 22753
Would something like this not satisfy your requirement rather than requery the database:
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()
This returns the number of rows affected by the command. Sample taken from here.
and for the select
Dim command2 New SqlCommand("Select into locationChangeTable (Col1,Col2,Col3) Values ('Val','Val2','Val3')", connection1)
connection1.Open()
returnValue = command1.ExecuteNonQuery()
connection1.Close()
Upvotes: 1