Problem using fill method on data adapter
-
okay, I'm a baby programmer, so don't laugh if this question is too obvious, but I've been stuck on this for hours now Very simple assignment - select data from an access data base using a data adapter and use the fill method to populate a data set I've looked at several examples that I've found on line and don't see what's wrong with my code. I always get a message on the adapter.fill line saying 'no value passed for one or more parameters' I see examples that dont just say adapter.fill(datasetname) and others that others that give a name for the name for the results within the data set, but I can't get either of these to work heres the latest attempt Thanks Protected Const CANDIDATESRESULTS As String = "Results" Protected connection As OleDbConnection = New OleDbConnection(connectionString) Public Sub OneCandidate(ByVal CandID As String) Dim candidateInfo As String = "SELECT * FROM CandidatesResults where CandidatesReulsts.CandidateID = '" & CandID & "'" Dim candAdapter As OleDbDataAdapter = New OleDbDataAdapter(candidateInfo, connection) candAdapter.SelectCommand = New OleDbCommand(candidateInfo, connection) candAdapter.Fill(candData, CANDIDATESRESULTS) DG.DataSource = candData DG.DataBind() Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=..\..\SampleDataBase.notadb" Dim candData As DataSet = New DataSet
-
okay, I'm a baby programmer, so don't laugh if this question is too obvious, but I've been stuck on this for hours now Very simple assignment - select data from an access data base using a data adapter and use the fill method to populate a data set I've looked at several examples that I've found on line and don't see what's wrong with my code. I always get a message on the adapter.fill line saying 'no value passed for one or more parameters' I see examples that dont just say adapter.fill(datasetname) and others that others that give a name for the name for the results within the data set, but I can't get either of these to work heres the latest attempt Thanks Protected Const CANDIDATESRESULTS As String = "Results" Protected connection As OleDbConnection = New OleDbConnection(connectionString) Public Sub OneCandidate(ByVal CandID As String) Dim candidateInfo As String = "SELECT * FROM CandidatesResults where CandidatesReulsts.CandidateID = '" & CandID & "'" Dim candAdapter As OleDbDataAdapter = New OleDbDataAdapter(candidateInfo, connection) candAdapter.SelectCommand = New OleDbCommand(candidateInfo, connection) candAdapter.Fill(candData, CANDIDATESRESULTS) DG.DataSource = candData DG.DataBind() Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=..\..\SampleDataBase.notadb" Dim candData As DataSet = New DataSet
Your code is a little out of order... You are dim'ing your connection string and your dataset after you've already connected to the database and attempted to fill your dataset. Try this: Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=..\..\SampleDataBase.notadb" Dim candData As DataSet = New DataSet Dim con As OleDbConnection = New OleDbConnection(connectionString) Public Sub OneCandidate(ByVal CandID As String) Dim candidateInfo As String = "SELECT * FROM CandidatesResults where CandidatesResults.CandidateID = '" & CandID & "'" Dim candAdapter As OleDbDataAdapter = New OleDbDataAdapter(candidateInfo, con) candAdapter.Fill(candData, CANDIDATESRESULTS) DG.DataSource = candData DG.DataBind() -- modified at 15:09 Monday 17th July, 2006
-
Your code is a little out of order... You are dim'ing your connection string and your dataset after you've already connected to the database and attempted to fill your dataset. Try this: Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=..\..\SampleDataBase.notadb" Dim candData As DataSet = New DataSet Dim con As OleDbConnection = New OleDbConnection(connectionString) Public Sub OneCandidate(ByVal CandID As String) Dim candidateInfo As String = "SELECT * FROM CandidatesResults where CandidatesResults.CandidateID = '" & CandID & "'" Dim candAdapter As OleDbDataAdapter = New OleDbDataAdapter(candidateInfo, con) candAdapter.Fill(candData, CANDIDATESRESULTS) DG.DataSource = candData DG.DataBind() -- modified at 15:09 Monday 17th July, 2006
thanks I can get this code to 'work' meaning not blowing up by dim the datagrid (Dim CandDG As DataGrid = New DataGrid) inside the class that contains this public sub the problem is the assignment calls for me to pass the data from the class to a form that calls the class. I haven't been able to get that to work
-
thanks I can get this code to 'work' meaning not blowing up by dim the datagrid (Dim CandDG As DataGrid = New DataGrid) inside the class that contains this public sub the problem is the assignment calls for me to pass the data from the class to a form that calls the class. I haven't been able to get that to work
To pass the dataset from the class to the form you will need to modify the parameters of your method. Instead of just passing the ID string, you will also need to pass the dataset. But you will have to pass it by reference instead of by value. (passing by value will never change the original variable on the form side, by reference will) So it will look more like this: Public Sub MyMethodName(ByVal myID as String, ByRef myDataSet as DataSet) That should get you started.