0
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    Dim bs As New BindingSource

    m_DataAdapter = New OleDbDataAdapter("SELECT * FROM Table1 ORDER BY ID", "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Users\rebel23\Desktop\sampledata.mdb")

    m_DataAdapter.Fill(m_DataSet)

    bs.DataSource = m_DataSet.Tables(0)
    BindingNavigator1.BindingSource = bs
    txtAnimal.DataBindings.Add("Text", bs, "TextBox6.text")
    txtSpecies.DataBindings.Add("Text", bs, "TextBox7.text")

In the above code i want to change the "data source" and declare it as TextBox1.text So that the user will decide the data source at run time... Also i want the same for 'Table1' and 'ID' but how to do that??

2
  • Did you try not putting "" around the textbox name in the binding? Commented May 31, 2013 at 20:44
  • the error is right now in "data source"... first let me correct that and then the other parts will be compiled for errors Commented Jun 1, 2013 at 11:16

2 Answers 2

1
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    Dim bs As New BindingSource
    Dim myTableName As String
    Dim myOrderingColumn As String
    Dim mybind1 As String
    Dim mybind2 As String

    myTableName = TextBox3.Text
    myOrderingColumn = TextBox4.Text
    mybind1 = TextBox6.Text
    mybind2 = TextBox7.Text

    m_DataAdapter = New OleDbDataAdapter("SELECT * FROM " & myTableName & " ORDER BY " & myOrderingColumn, "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & TextBox5.Text)

    m_DataAdapter.Fill(m_DataSet)

    bs.DataSource = m_DataSet.Tables(0)
    BindingNavigator1.BindingSource = bs
    txtAnimal.DataBindings.Add("Text", bs, "" & TextBox6.Text & "")
    txtSpecies.DataBindings.Add("Text", bs, "" & TextBox7.Text & "")


End Sub

hey i got the code man !!!! its working .... thanks a lot for your support and suggestions @matzone

Sign up to request clarification or add additional context in comments.

Comments

0

I did it in different way ..

Dim myConn = New OleDb.OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\rebel23\Desktop\sampledata.mdb;Jet OLEDB:Database Password=mypass")

Dim cmd As OleDbCommand 
Dim ds as DataSet = New DataSet

myConn.Open() '--> open conn
cmd = New OleDbCommand("SELECT * FROM Table1 ORDER BY ID", myConn)

cmd.Fill(ds, "predator") ' ---> named dataset as Predator

txtAnimal.DataBindings.Add("Text", ds.Tables("predator"), "'" & TextBox6.text & "'")
txtSpecies.DataBindings.Add("Text",ds.Tables("predator"), "'" & TextBox7.text & "'")

' ....
' .....

cmd.Dispose()
ds.Dispose()
cnn.Close()

5 Comments

my questions are still unanswered !!!! what about "data source" ??????? @matzone
tried myTableName = TextBox3.Text myOrderingColumn = TextBox4.Text m_DataAdapter = New OleDbDataAdapter("SELECT * FROM " & myTableName & " ORDER BY " & myOrderingColumn, "Provider=Microsoft.Jet.OLEDB.4.0; DataSource=" & TextBox5.Text) and everything as you told but still getting an error (run time) error details- System.Data.OleDb.OleDbException was unhandled ErrorCode=-2147467259 Message=Could not find installable ISAM. Source=Microsoft JET Database Engine @matzone
My first requirement is that the user should be able to declare the data source.... in your code whre is the user telling the data source.. its already defined in the code... the topic is -declare “data source” in a connection string as 'variable' in VB.NET
declaring data source at run time
@ʞuɐɹdRebel: in the first line .. there's declaring connection with the datasource ! .. so, what do you want ? .. what kinda text in textbox6 an 7 ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.