I've been looking over a bunch of code snippets and I'm just not understanding what is going on there. Some help in understanding the connection, reading/manipulation, and closing process would be more than appreciated.
I keep reading all about these DataAdapters, Ole and Sql and Sqlce and I don't know which to use or whatever.
I made a database in VB.NET 2010 that came out as database.sdf and I selected the Local Database option (I assume this is relevant?). I then populated the database with a row of data with column titles and a primary key. The table contains many different columns, but for test purposes, the following is relevant:
This is what I pieced together, but I'm quite sure it's just not even in the right direction...
Obviously code help would be phenomenal, but if anyone is willing to break this process down in English as well, that'd be super fantastic.
Dim conn As SqlConnection = New SqlConnection("Data Source=G:\Programming\VB.NET\TEST\TEST\db_test.sdf")
Dim ds As New db_test
Dim sql As New SqlCommand("SELECT * FROM Locations WHERE CITY='Brunswick'")
conn.Open()
(I have no idea what this is actually referring to, I am just trying to read data with these commands below that seemed to pop up a lot in forums...)
Dim sdr As SqlDataReader = sql.ExecuteReader
While sdr.Read = True
MsgBox(sdr.Item("CITY") & " " & sdr.Item("BOUND_X"))
End While
sdr.Close()
conn.Close()
The data access code in .NET is grouped into what is ADO.NET. You can read for reference here:
http://msdn.microsoft.com/en-us/library/h43ks021(v=vs.100).aspx
Regarding the code:
More technically correct code would look like this may be found here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.