SQL cross join datagrid error

liunx

Guest
Hi can anyone help me as I have encountered another problem on the coding. I have use a cross join method in the SQL statement to check on two tables in the database for the result instead of appearing the result in the datagrid it appear any error message.

This is my coding:

Dim SelectedItem, keyword, setting, As String

keyword = txtKeyword.Text
SelectedItem = DDLCategory.SelectedValue
setting = " = "

Dim queryString As String = "SELECT * FROM tblUser_super cross join tbluser_normal Where " & SelectedItem & setting & "'" & keyword & "'"
Dim mycommand As SqlClient.SqlCommand
mycommand = New SqlClient.SqlCommand(queryString, myconnection)

Dim dataAdapter As System.Data.IDbDataAdapter = New System.data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = mycommand

Dim data As System.data.DataSet = New System.Data.DataSet
dataAdapter.Fill(data)

List.DataSource = data
List.DataBind()


Error message:

Server Error in '/ATS1' Application.
Ambiguous column name 'DeptID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Ambiguous column name 'DeptID'.

The code must be written under *.aspx.vb. Can anyone show me an example on the coding?

Thank you for your help.It appears that "DeptID" column exists in the two tables "tblUser_super" and "tbluser_normal", try using "tblName.columnName", for instance
tbluser_normal.DeptID, and in you code you can try this
"SELECT * FROM tblUser_super cross join tbluser_normal Where tbluser_normal." & SelectedItem & setting & "'" & keyword & "'"
And i dont know if you mean to use "IDbDataAdapter" or no, but i think "SqlDataAdapter" will work.Cipher , really thank alot for your help
 
Back
Top