svibuk
05-14-2009, 08:25 AM
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 dataset
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 cannot find table(0)
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 dataset
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 cannot find table(0)