Results 1 to 7 of 7

Thread: MS ACCESS with VB.NET+Connection help needed

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    24

    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
    Last edited by sourind; Feb 25th, 2007 at 04:49 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    24

    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
    Last edited by sourind; Feb 25th, 2007 at 04:51 AM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    24

    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    24

    Re: MS ACCESS with VB.NET+Connection help needed

    anyone?

  7. #7
    New Member
    Join Date
    Feb 2007
    Location
    Phil
    Posts
    13

    Re: MS ACCESS with VB.NET+Connection help needed

    Opps! I modified your code hope this help.

    VB Code:
    1. 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width