I am new to VB.Net
My old VB 6 code is:
Set conn = my connection string
conn.open
Set ce = conn.Execute("select * from table where id = 1")
If ce.EOF Then conn.Execute ("insert into table set name = '" & Text1.Text & "'")
I want get sql table field and if eof then add record using VB.NET. Thanks for help.
Your old vb6 code was awful: it was vulnerable to sql injection, and badly inefficient because there’s no need to ever bring the results back to the client. There’s no excuse for either of those, even in vb6. Let’s fix both those issues with your vb.net migration. Your new code should look like this:
And then call the function like this:
Note that most of the techniques I showed in this code were also available and the best practice in vb6 — namely the better sql and query parameters — even if the way you go about them looked different in vb6.