soniarose
جمعه 10 مهر 1388, 11:57 صبح
سلام من میخوام کدی برای جستجو بنویسم که بعد از پیدا کردن رکورد مورد نظر اون ستونها رو در datagridview نشون بده من این کد رو مینویسم لطفا شما کاملش کنید
Dim strcon1 As String
' Dim com1 As SqlCommand
Dim da As SqlDataAdapter
Dim strsql1 As String
Dim con1 As SqlConnection
Dim ds1 As New DataSet
Dim dt As New DataTable
ds1.Clear()
strsql1 = "select * from table1 where "
strcon1 = "Data Source=(local);Initial Catalog=tel;Integrated Security=True"
If TextBox1.Text <> "" Then strsql1 += "id like '%" + TextBox1.Text + "' and "
If TextBox2.Text <> "" Then strsql1 += "name='" + TextBox2.Text + "' and "
If TextBox3.Text <> "" Then strsql1 += "famil='" + TextBox3.Text + "' and "
If strsql1 = "select * from table1 where " Then
strsql1 = "select * from table1"
Else
strsql1 = strsql1.Remove(strsql1.Length - 4, 4)
End If
con1 = New SqlConnection(strcon1)
con1.Open()
da = New SqlDataAdapter(strsql1, con1)
da.Fill(ds1, "table1")
con1.Close()
ds1.Dispose()
da.Dispose()
MsgBox(" ستون پیدا شد" + dt.Rows.Count.ToString)
Dim strcon1 As String
' Dim com1 As SqlCommand
Dim da As SqlDataAdapter
Dim strsql1 As String
Dim con1 As SqlConnection
Dim ds1 As New DataSet
Dim dt As New DataTable
ds1.Clear()
strsql1 = "select * from table1 where "
strcon1 = "Data Source=(local);Initial Catalog=tel;Integrated Security=True"
If TextBox1.Text <> "" Then strsql1 += "id like '%" + TextBox1.Text + "' and "
If TextBox2.Text <> "" Then strsql1 += "name='" + TextBox2.Text + "' and "
If TextBox3.Text <> "" Then strsql1 += "famil='" + TextBox3.Text + "' and "
If strsql1 = "select * from table1 where " Then
strsql1 = "select * from table1"
Else
strsql1 = strsql1.Remove(strsql1.Length - 4, 4)
End If
con1 = New SqlConnection(strcon1)
con1.Open()
da = New SqlDataAdapter(strsql1, con1)
da.Fill(ds1, "table1")
con1.Close()
ds1.Dispose()
da.Dispose()
MsgBox(" ستون پیدا شد" + dt.Rows.Count.ToString)