You definitely know these commands just as SqlCommand, SqlConnection,SqlDataAdapter, SqlDataReader ect. and I will explain how the command works
A SqlConnection object represents a unique session to a SQL Server data source. With a client/server database system, it is equivalent to a network connection to the server. SqlConnection is used together with SqlDataAdapter and SqlCommand to increase performance when connecting to a Microsoft SQL Server database. For all third-party SQL server products, and other OLE DB-supported data sources, use OleDbConnection.When you create an instance of SqlConnection, all properties are set to their initial values. For a list of these values. to execute command
SqlConnection is used Initializes a new instance of the SqlConnection class, to put the string into a SqlConnection,just like SqlConnection(String)
Code:
Dim ConnString as string = "Data Source=192.168.1.1\SQLEXPRESS;Initial Catalog=Contoh;
User=admin; Pwd=1" ' your connection string here ..
sqlclient.sqlconnection(ConnString) 'put the string with sqlconnection
SqlCommand is used Initializes a new instance of the SqlCommand class, you can use the SELECT,INSERT,UPDATE,DELETE command with SQLCommand, SQLCommand will execute these commands in the database, surely you must have a connection string to execute the query. to added your connection string just put the code, SqlCommand(String, SqlConnection)
Code:
Dim ConnString as string = "Data Source=192.168.1.1\SQLEXPRESS;Initial Catalog=Contoh; User=admin; Pwd=1" ' your connection string here ..
sqlclient.sqlconnection(ConnString) 'put the string with sqlconnection
SqlClient.SqlCommand.Connetion = sqlclient.sqlconnection(ConnString) 'and hook it up with sqlclient.command
The SqlDataAdapter, serves as a bridge between a DataSet and SQL Server for retrieving and saving data. The SqlDataAdapter provides this bridge by mapping Fill, which changes the data in the DataSet to match the data in the data source.
SqlDataAdapter is used Initializes a new instance of the SqlDataAdapter class, how its mapping with dataset.
Code:
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
This info is really professional. the right people will appreciate it. pip in custom essay Good luck!
ReplyDelete