MS ACCESS with VB.NET+Connection help needed
i have a database det1,and a table in it (table2) like below
field1 field2 field3
12 13 14
15 16 17
18 19 20
the datatypes are all "Text"
i need to access the row whose field1=15
when i use the following code ,i get the error
No value given for one or more required parameters
with the line
sa.Fill(ds, "table2")
highlighted
Public Function GetPupil(ByVal id As Integer)
Dim conn As OleDb.OleDbConnection = GetConnection()
Dim i As Integer
i = 15
Try
Dim sql As String = "Select * from table2 WHERE Field1=" & i.ToString()Dim sa As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, conn)
Dim ds As New DataSet
Try
sa.Fill(ds, "table2")
Finally
sa.Dispose()
End Try
Return ds
Finally
conn.Close()
conn.Dispose()
End Try
End Function
is the line
Dim sql As String = "Select * from table2 WHERE Field1=" & i.ToString()
correct?? or is there anything else wrong?
can anyone help me with this?
thnking in advance
Re: MS ACCESS with VB.NET+Connection help needed
You say that your database contains a table named "table1" yet your query includes "table2". Could that be your issue?
Re: MS ACCESS with VB.NET+Connection help needed
extremely sorry,,,,that should be table2...(i my database)
changed it
but still the problem persists
Re: MS ACCESS with VB.NET+Connection help needed
I just realised that you said that all your columns are text. This is again a good reason to use parameters and not literal values. Literal text values in SQL statements must be enclosed in single quotes. If you'd used a parameter this wouldn't have been an issue. As you're inserting a literal value into the SQL code you need to enclose it in single quotes or else it will get ignored, which is what's happening in your case.
This all begs the question, why are you using text columns? It looks like all your values are numbers so wouldn't it be more appropriate to use number columns?
Also, this is a duplicate post. Do not post the same question more than once. If you'd given us all the information in your other thread we could have solved the problem there.
Re: MS ACCESS with VB.NET+Connection help needed
actually using single quotes does not solve the problem
and how to use parameters in this case
pls help
Re: MS ACCESS with VB.NET+Connection help needed
Re: MS ACCESS with VB.NET+Connection help needed
Opps! I modified your code hope this help.
VB Code:
Dim sql As String = "Select * from table2 WHERE Field1= '" & i.ToString() & "' "
if not just put a Val( "you string" ) because your dealing with integers.
Hope this help. :) :D