HOME > .NET Framework > Forum > VB ผมต้องแก้ตรงไหนครับ รบกวนด้วยครับ Error 1 Value of type 'String' cannot be converted to 'System.Data.SqlClient.SqlCommand'.
VB ผมต้องแก้ตรงไหนครับ รบกวนด้วยครับ Error 1 Value of type 'String' cannot be converted to 'System.Data.SqlClient.SqlCommand'.
Dim objConn As SqlConnection
Dim scom As SqlCommand
Dim dtAdapter As SqlDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Data Source=192.9.3.82;Initial Catalog=PA4BRANCH;User ID=sa;Password=P@ssw0rd"
objConn = New SqlDataAdapter(strConnString) '***ผิดบรรทัดนี้ครับ***'
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM inventory WHERE 1=1 "
If strKeyWord <> "" Then
strSQL = strSQL & " AND Name Like '%" & strKeyWord & "%' "
End If
dtAdapter = New SqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Me.myDgv.DataSource = dt
Dim objConn As New System.Data.SqlClient.SqlConnection
Dim objCmd As New System.Data.SqlClient.SqlCommand
Dim dtAdapter As New System.Data.SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim strConnString,strSQL As String
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
strSQL = "SELECT * FROM customer"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing