Saturday, March 17, 2012

SqlCommand, SqlConnection,SqlDataAdapter, SqlDataReader in vb.net

You definitely know these commands just as SqlCommand, SqlConnection,SqlDataAdapter, SqlDataReader ect. and I will explain how the command works
Dim Da As New SqlClient.SqlDataAdapter 
Dim Ds As New DataSet
Da.SelectCommand = SqlClient.SqlCommand 
Da.Fill(ds, "grafik") 'Fill SqlCommand by maaping into a dataset

To create a SqlDataReader, you must call the ExecuteReader method of the SqlCommand object, instead of directly using a constructor, 

Code:

Dim Str As String = "Data Source=192.168.1.1\SQLEXPRESS;Initial Catalog=Contoh; User=admin; Pwd=1"  Dim cnt As New SqlClient.SqlConnection(Str)  'connection string Dim cmd As New SqlClient.SqlCommand  Dim read As SqlClient.SqlDataReader             cnt.Close()             cnt.Open()             With cmd                 .Connection = cnt                 .CommandText = "select * from grafik where nomor ='" & cari.Trim & "'"                 read = cmd.ExecuteReader(CommandBehavior.SingleRow)                  If read.Read Then                     MsgBox("Read table ", MsgBoxStyle.Information)                  Else                     MsgBox("Unread table", MsgBoxStyle.Information)                 End If             End With

related articles Insert, Select, Update and Delete in VB.net

Reading Source msdn

1 comment:

  1. This info is really professional. the right people will appreciate it. pip in custom essay Good luck!

    ReplyDelete