Results 1 to 10 of 10

Thread: Why this exception?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Why this exception?

    Code:
    con = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=db1.mdb")
    02	con.Open()
    03	cmd = New OleDbCommand("Select * from Table1 where Name='gautam';" & "Select * from Table1 where Name='arijit';" & "Select * from Table1 where Name='muah'", con)
    04	Dim dr As OleDbDataReader
    05	dr = cmd.ExecuteReader()
    06	dr.Read()
    07	textBox1.Text = dr(0).ToString()
    08	textBox2.Text = dr(1).ToString()
    09	textBox3.Text = dr(2).ToString()
    10	textBox4.Text = dr(3).ToString()
    11	dr.NextResult()
    12	dr.Read()
    13	textBox5.Text = dr(0).ToString()
    14	textBox6.Text = dr(1).ToString()
    15	textBox7.Text = dr(2).ToString()
    16	textBox8.Text = dr(3).ToString()
    17	dr.NextResult()
    18	dr.Read()
    19	textBox9.Text = dr(0).ToString()
    20	textBox10.Text = dr(1).ToString()
    21	textBox11.Text = dr(2).ToString()
    22	textBox12.Text = dr(3).ToString()
    23	dr.Close()
    24	cmd.Dispose()
    25	con.Close()
    i am getting this exception:
    Name:  Untitled.jpg
Views: 124
Size:  10.5 KB

    please help

  2. #2
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: Why this exception?

    I don't think this is valid, you concatenated 3 select statement, which I've never seen before, where you should only be using one
    Code:
    cmd = New OleDbCommand("Select * from Table1 where Name='gautam';" & "Select * from Table1 where Name='arijit';" & "Select * from Table1 where Name='muah'", con)
    You should be using something like :
    Code:
    Select * from Table1 where Name='gautam' OR Name = 'arijit' OR Name = 'muah';
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Re: Why this exception?

    nope........you changed the entire meaning of my sql statement

    first i select the entire row where Name ='gautam' ,then i select entire row where name='arijit' and last i select entire row where name='much'

    Then i populate the datareader with these three sql statements one aftre another using the nextresult() and populate the corresponding textbox.......

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Why this exception?

    As far as I know Microsoft.Jet.Oledb doesn't support multiple queries in single query statement.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: Why this exception?

    Quote Originally Posted by HowTo View Post
    nope........you changed the entire meaning of my sql statement

    first i select the entire row where Name ='gautam' ,then i select entire row where name='arijit' and last i select entire row where name='much'

    Then i populate the datareader with these three sql statements one aftre another using the nextresult() and populate the corresponding textbox.......
    I understand that, but what I'm actually wondering is can you really use 3 select statement within the same OleDbCommand ?
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Re: Why this exception?

    Quote Originally Posted by Pradeep1210 View Post
    As far as I know Microsoft.Jet.Oledb doesn't support multiple queries in single query statement.
    then it means i cant use the nextResult() of the datareader when i am using the oledb?

  7. #7
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Why this exception?

    Quote Originally Posted by HowTo View Post
    then it means i cant use the nextResult() of the datareader when i am using the oledb?
    Atleast not with the Microsoft.Jet.Oledb provider as far as I know.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: Why this exception?

    Quote Originally Posted by HowTo View Post
    then it means i cant use the nextResult() of the datareader when i am using the oledb?
    Looks like you could do it using the SqlCommand instead of the OleDbCommand as you can see here.
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

  9. #9
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: Why this exception?

    Quote Originally Posted by stlaural View Post
    Looks like you could do it using the SqlCommand instead of the OleDbCommand as you can see here.
    ya actually i was also trying to do it by having a look at the same page of the msdn.Anyways,nice to know that oledb cant handle these kinds of sql queries......

    may i know what are these sql queries called(which contains more than 1 select statement as shown in the code)?

  10. #10
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Why this exception?

    It is not limited to SELECT type queries only. It can be any valid sql query.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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