Sql string doesnt accept combobox selected text

  • Thread starter Thread starter kyriakos70
  • Start date Start date
K

kyriakos70

Guest
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim ConnectionString As String
Dim binding As New BindingSource

ConnectionString = ("Integrated Security = true;Initial catalog = " & ComboBox2.SelectedText.ToString & ";Data Source = " & ComboBox1.SelectedText & "; ")
Dim SQL As String = "SELECT * FROM Table_1"
Dim conn As SqlConnection = New SqlConnection(ConnectionString)

' open the connection


'Create a SqlDataAdapter object
Dim adapter1 As SqlDataAdapter = New SqlDataAdapter(SQL, conn)

' Call DataAdapter's Fill method to fill data from the
' Data Adapter to the DataSet
Dim ds As New DataSet
'ds.Tables.Add("Table_1")
conn.Open()
adapter1.Fill(ds, "Table_1")
conn.Close()
binding.DataSource = ds
binding.DataMember = "Table_1"
DataGridView1.DataSource = binding

End Sub

the above code doesn't accept combobox2.selectedtext database name but accepts the combobox1

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim ConnectionString As String
Dim binding As New BindingSource
ConnectionString = ("Integrated Security = true;Initial catalog = logistiki;Data Source = " & ComboBox1.SelectedText & "; ")
Dim SQL As String = "SELECT * FROM Table_1"
Dim conn As SqlConnection = New SqlConnection(ConnectionString)

' open the connection


'Create a SqlDataAdapter object
Dim adapter1 As SqlDataAdapter = New SqlDataAdapter(SQL, conn)

' Call DataAdapter's Fill method to fill data from the
' Data Adapter to the DataSet
Dim ds As New DataSet
'ds.Tables.Add("Table_1")
conn.Open()
adapter1.Fill(ds, "Table_1")
conn.Close()
binding.DataSource = ds
binding.DataMember = "Table_1"
DataGridView1.DataSource = binding

End Sub

this code works but I need to select the database as the server from combobox1, is it a bug? I am using VS 2015 Community edition and sql sever 2014 express windows 7 x64 professional.

Continue reading...
 
Back
Top