Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i want to select a sql table using ado in my visual basic program

Status
Not open for further replies.

momchaffeivb

Programmer
Jan 18, 2012
2
i want to select a sql table using ado in my visual basic program


Imports System.Data.SqlClient
Imports System.Data
Public Class select_data
Private Sub Beep_Button1_Click(sender As System.Object, e As System.EventArgs) Handles Beep_Button1.Click
Dim dt As New DataTable()
Dim obj As New Ado
dt = GetStudentByName(Table.Text)
BindingSource1.DataSource = dt
DataGridView1.DataSource = BindingSource1



End Sub
Public Function GetStudentByName(ByVal name As String) As DataTable
Dim con As New SqlConnection("Data Source=.;initial catalog= test;integrated security=True")
Dim com As New SqlCommand

con.Open()
com.CommandText = "select * from " + Table.Text + ""
com.CommandType = CommandType.Text
com.Connection = con

Dim dr As SqlDataReader = com.ExecuteReader()
Dim dt As DataTable = New DataTable()
dt.Load(dr)
If dt.Rows.Count <> 0 Then
Return dt
con.Close()
Else
MsgBox("ERROR !", MsgBoxStyle.Critical)
Return Nothing
con.Close()
End If
End Function
End Class




this is my code are there any think bad (table)is a textbox
 
Your code isn't VBA but VB.NET I guess.
I'd post here:
forum796

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top