essam_saeed Posted October 2, 2004 Posted October 2, 2004 Good afternoon \ morning everyone I am new in visual basic.net And I hope a helping from you My best programming language is VB.6, because with MS SQL-SERVER But l want to move to VB.net When I saw some codes in this language I could not understand it easy I need any answer for the following questions: - How to make connection to database - How to read data from database - How to write , Update Your small Brother Quote
Mykre Posted October 4, 2004 Posted October 4, 2004 'Open and close a connection using the SQL Client .NET Data Provider. Dim cnOleDb As New OleDbConnection cnOleDb.ConnectionString = "Provider=SQLOLEDB; "Data Source=(local);InitialCatalog=Northwind;..." cnOleDb.Open() ... cnOleDb.Close() 'Open and close a connection using the SQL Client .NET Data Provider. Dim cnSql As New SqlConnection cnSql.ConnectionString = "Data Source=(local);" & _ "Initial Catalog=Northwind;..." cnSql.Open() ... cnSql.Close() 'Using OLEDBClient Returning and Displaying Data from a Datareader Dim strConn, strSQL As String strConn = "Provider=SQLOLEDB;Data Source=(local)\NetSDK;" & _ "Initial Catalog=Northwind;Trusted_Connection=Yes;" Dim cn As New OleDbConnection(strConn) cn.Open() strSQL = "SELECT CustomerID, CompanyName FROM Customers" Dim cmd As New OleDbCommand(strSQL, cn) Dim rdr As OleDbDataReader = cmd.ExecuteReader() While rdr.Read() Console.WriteLine(rdr("CustomerID") & " � " & rdr("CompanyName")) End While rdr.Close() 'Faster Method Dim strConn, strSQL As String strConn = "Provider=SQLOLEDB;Data Source=(local)\NetSDK;" & _ "Initial Catalog=Northwind;Trusted_Connection=Yes;" Dim cn As New OleDbConnection(strConn) cn.Open() strSQL = "SELECT CustomerID, CompanyName FROM Customers" Dim cmd As New OleDbCommand(strSQL, cn) Dim rdr As OleDbDataReader = cmd.ExecuteReader() Dim intCustomerIDOrdinal As Integer = rdr.GetOrdinal("CustomerID") Dim intCompanyNameOrdinal As Integer = rdr.GetOrdinal("CompanyName") While rdr.Read() Console.WriteLine(rdr(intCustomerIDOrdinal) & " � " & _ rdr(intCompanyNameOrdinal)) End While rdr.Close() or ... Dim rdr As OleDbDataReader = cmd.ExecuteReader() Dim intCustomerIDOrdinal As Integer = rdr.GetOrdinal("CustomerID") Dim intCompanyNameOrdinal As Integer = rdr.GetOrdinal("CompanyName") While rdr.Read() Console.WriteLine(rdr.GetString(intCustomerIDOrdinal) & " � " & _ rdr.GetString(intCompanyNameOrdinal)) End While rdr.Close() 'Connecting to a Database and filling a DataSet using a Dataadapter.fill Dim strConn, strSQL As String strConn = "Provider=SQLOLEDB;Data Source=(local)\NetSDK;" & _ "Initial Catalog=Northwind;Trusted_Connection=Yes;" strSQL = "SELECT CustomerID, CompanyName, ContactName, Phone " & _ "FROM Customers" Dim da As New OleDbDataAdapter(strSQL, strConn) Dim ds As New DataSet() da.Fill(ds) Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.