VisualStudio 2008 Smart Device Project SQL bağlantısı DataGrid

Public Class Form3
Dim SqlConnStr As String = “server=192.168.0.144;database=MACELLAN;uid=fdonmez;pwd=123456;”
Dim SqlConn As New System.Data.SqlClient.SqlConnection(SqlConnStr)
Dim kullanici As String

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Focus()
Try
SqlConn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message, “baglantı yok”)

Me.Close()
End Try
If SqlConn.State = 1 Then

Me.Text = “sql bağlandı”
End If

SqlConn.Close()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> “” Then
SqlConn.Open()

 

Dim mySelectQuery As String = “SELECT MATERIAL,R.STEXT RENK,B.STEXT BEDEN,STOCKPLACE,BATCHNUM,TOTALSTOCK,QUNIT,WAREHOUSE,SPECIALSTOCK FROM IASINVSTOCK,IASVAROPTIONX B WITH (NOLOCK), IASVAROPTIONX R WITH (NOLOCK) WHERE WAREHOUSE=’400′ AND STOCKPLACE LIKE ‘___%’ AND TOTALSTOCK>0 AND SUBSTRING(MATERIAL,1,6) = ‘” & TextBox1.Text & “‘ AND B.VARIANTKEY=’RB’ AND B.ATTRIBUTEKEY=’01′ AND B.OPTIONKEY=SUBSTRING(VOPTIONS,4,2) AND R.VARIANTKEY=’RB’ AND R.ATTRIBUTEKEY=’02′ AND R.OPTIONKEY=SUBSTRING(VOPTIONS,10,3) ORDER BY R.STEXT,B.STEXT,STOCKPLACE ;”
Dim SqlComm As New System.Data.SqlClient.SqlCommand(mySelectQuery, SqlConn)

Dim reader As System.Data.SqlClient.SqlDataReader
reader = SqlComm.ExecuteReader()
Dim table As New DataTable()
table.Load(reader)
DataGrid1.DataSource = table
SqlConn.Close()
End If
End Sub
End Class

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir