Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. error --canot find table(0)

error --canot find table(0)

Scheduled Pinned Locked Moved ASP.NET
cssdatabasehelpannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    svknair
    wrote on last edited by
    #1

    i have 2 tables from where the data is taken table 1 and table 2 table1 has user, country, city table2 has country,city wht i need is 1) selecting user with condition of country and city dropdownlists = the output can be multiple & after exceution of he query need to get the users 2) selecting fields from table2 from the grid depending on the id( i am getting the selected multiple id from the grid.== uid) then inserting the user , country , city in table1 with country, city selected fom table 2 if table1 has the combination of user , country , city then update else insert i have written the code but not getting the desired output if i use in the below way ie line1 & line2 then i get no error but only the last record in for loop gets affected and if i use line2 and then line1 i get sqlstr= "SELECT user FROM table1 " _ & " WHERE country='" & drpcountry.SelectedItem.Text & "' AND city='" & drpcity.SelectedItem.Text & "'" USERREADER = cmdMain.ExecuteReader() If USERREADER.HasRows Then While USERREADER.Read dim uname= USERREADER("user").ToString.Trim msgbox(uname) sqlstr= "select [country],[city] FROM table2 WHERE ID in( " & UID & ") order by country" '''''''''''''''''''' executing the query using If ds.Tables(0).Rows.Count > 0 Then Dim count = ds.Tables(0).Rows.Count For i = 0 To count - 1 Dim datacountry = ds.Tables(0).Rows(i).Item("country").ToString() Dim datacity = ds.Tables(0).Rows(i).Item("city").ToString() sqlstr= "IF EXISTS (SELECT user, country,city FROM table1 " _ & " WHERE user='" & uname & "'" _ & " AND country='" & datacountry & "' AND city='" & datacity & "')" _ & " UPDATE table1 set user='" & uname & "' " _ & " WHERE country='" & datacountry & "' AND city='" & datacity & "' " _ & " Else " _ & " INSERT INTO table1(user,country,city) " _ & " VALUES ('" & uname & "','" & datacountry & "','" & datacity & "')" Next ''''''' line1 '''''''''''''''''''' executing the query using dataset ''''''''line2 End If End While End If End If getting error cannnot find table(0)

    D 1 Reply Last reply
    0
    • S svknair

      i have 2 tables from where the data is taken table 1 and table 2 table1 has user, country, city table2 has country,city wht i need is 1) selecting user with condition of country and city dropdownlists = the output can be multiple & after exceution of he query need to get the users 2) selecting fields from table2 from the grid depending on the id( i am getting the selected multiple id from the grid.== uid) then inserting the user , country , city in table1 with country, city selected fom table 2 if table1 has the combination of user , country , city then update else insert i have written the code but not getting the desired output if i use in the below way ie line1 & line2 then i get no error but only the last record in for loop gets affected and if i use line2 and then line1 i get sqlstr= "SELECT user FROM table1 " _ & " WHERE country='" & drpcountry.SelectedItem.Text & "' AND city='" & drpcity.SelectedItem.Text & "'" USERREADER = cmdMain.ExecuteReader() If USERREADER.HasRows Then While USERREADER.Read dim uname= USERREADER("user").ToString.Trim msgbox(uname) sqlstr= "select [country],[city] FROM table2 WHERE ID in( " & UID & ") order by country" '''''''''''''''''''' executing the query using If ds.Tables(0).Rows.Count > 0 Then Dim count = ds.Tables(0).Rows.Count For i = 0 To count - 1 Dim datacountry = ds.Tables(0).Rows(i).Item("country").ToString() Dim datacity = ds.Tables(0).Rows(i).Item("city").ToString() sqlstr= "IF EXISTS (SELECT user, country,city FROM table1 " _ & " WHERE user='" & uname & "'" _ & " AND country='" & datacountry & "' AND city='" & datacity & "')" _ & " UPDATE table1 set user='" & uname & "' " _ & " WHERE country='" & datacountry & "' AND city='" & datacity & "' " _ & " Else " _ & " INSERT INTO table1(user,country,city) " _ & " VALUES ('" & uname & "','" & datacountry & "','" & datacity & "')" Next ''''''' line1 '''''''''''''''''''' executing the query using dataset ''''''''line2 End If End While End If End If getting error cannnot find table(0)

      D Offline
      D Offline
      dotnetmember
      wrote on last edited by
      #2

      chk whether ur dataset has any tables. may be ur query is not returning any resultset.

      S S 2 Replies Last reply
      0
      • D dotnetmember

        chk whether ur dataset has any tables. may be ur query is not returning any resultset.

        S Offline
        S Offline
        svknair
        wrote on last edited by
        #3

        this code works fine for the first record in the loop it gives the error from second record if i execute the query after NEXT statement i dont get any error but only the last record frm the loop gets affected/executed not the earlier ones any solution /alteration in the code i have also used if DS.tables.count>o then before the IF DS.tables(0).rows.count>0

        1 Reply Last reply
        0
        • D dotnetmember

          chk whether ur dataset has any tables. may be ur query is not returning any resultset.

          S Offline
          S Offline
          sriram 1012
          wrote on last edited by
          #4

          Check DataSet return the Nullreferance or nt sriram

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups