Hey guys I need a little help here. I ran into a bit where i am programmatically setting up a dataAdapter. I already have a strongly typed dataset to put the data into I am just having problems getting it to work. I keep getting this error
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Exception: View Selected Sites Failed ---> System.Data.SqlClient.SqlException: The column prefix 'UNIT' does not match with a table name or alias name used in the query.
The thing is I have set up a table mapping with included column mappings which I though would solve the problem it did not. Below is my code modified to be generic that is. but it's all there.
Dim sdaSelectedSites As New SqlClient.SqlDataAdapter()
Dim scmdSelectedSites As New SqlClient.SqlCommand()
'setup the command object
scmdSelectedSites.Connection = sqlconn scmdSelectedSites.CommandType = CommandType.Text
'setup the parameters
With scmdSelectedSites.Parameters
'blah blah setting up
End With
'set the text of the select statment
sb.Append("SELECT UNIT.UNIT,UNIT.UNIT_ID, UNIT.MAX_EQUIP_LENGTH, "
sb.Append("UNIT.UNIT_NOTE, CLASS.CLASS_DESC "
sb.Append("WHERE UNIT.CLASS = CLASS.CLASS AND ("
sb.Append("(UNIT.UNIT_ID = @unit)"
scmdSelectedSites.CommandText = sb.ToString
'set up the column mappings
Dim myColumnMap(4) As System.Data.Common.DataColumnMapping
myColumnMap(0) = New System.Data.Common.DataColumnMapping("UNIT", "UNIT"
myColumnMap(1) = New System.Data.Common.DataColumnMapping("UNIT_ID", "UNIT_ID"
myColumnMap(2) = New System.Data.Common.DataColumnMapping("MAX_EQUIP_LENGTH", "MAX_EQUIP_LENGTH"
myColumnMap(3) = New System.Data.Common.DataColumnMapping("UNIT_NOTE", "UNIT_NOTE"
myColumnMap(4) = New System.Data.Common.DataColumnMapping("CLASS_DESC", "CLASS_DESC"
'setup the table mappings
Dim myTableMap As New System.Data.Common.DataTableMapping("Table", "Sites", myColumnMap)
'set up the data adapter
sdaSelectedSites.SelectCommand = scmdSelectedSites
sdaSelectedSites.TableMappings.Add(myTableMap)
'open a connection
SqlConn.Open()
'fill the dataset
sdaSelectedSites.Fill(mySites)
The bold line is where the error occurs. I am just not sure why it is crapping out. I have another designer built Data Adapter that uses the same Select (different where clause) and fills that same dataset with no errors.
Me confused help please. That'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Exception: View Selected Sites Failed ---> System.Data.SqlClient.SqlException: The column prefix 'UNIT' does not match with a table name or alias name used in the query.
The thing is I have set up a table mapping with included column mappings which I though would solve the problem it did not. Below is my code modified to be generic that is. but it's all there.
Dim sdaSelectedSites As New SqlClient.SqlDataAdapter()
Dim scmdSelectedSites As New SqlClient.SqlCommand()
'setup the command object
scmdSelectedSites.Connection = sqlconn scmdSelectedSites.CommandType = CommandType.Text
'setup the parameters
With scmdSelectedSites.Parameters
'blah blah setting up
End With
'set the text of the select statment
sb.Append("SELECT UNIT.UNIT,UNIT.UNIT_ID, UNIT.MAX_EQUIP_LENGTH, "
sb.Append("UNIT.UNIT_NOTE, CLASS.CLASS_DESC "
sb.Append("WHERE UNIT.CLASS = CLASS.CLASS AND ("
sb.Append("(UNIT.UNIT_ID = @unit)"
scmdSelectedSites.CommandText = sb.ToString
'set up the column mappings
Dim myColumnMap(4) As System.Data.Common.DataColumnMapping
myColumnMap(0) = New System.Data.Common.DataColumnMapping("UNIT", "UNIT"
myColumnMap(1) = New System.Data.Common.DataColumnMapping("UNIT_ID", "UNIT_ID"
myColumnMap(2) = New System.Data.Common.DataColumnMapping("MAX_EQUIP_LENGTH", "MAX_EQUIP_LENGTH"
myColumnMap(3) = New System.Data.Common.DataColumnMapping("UNIT_NOTE", "UNIT_NOTE"
myColumnMap(4) = New System.Data.Common.DataColumnMapping("CLASS_DESC", "CLASS_DESC"
'setup the table mappings
Dim myTableMap As New System.Data.Common.DataTableMapping("Table", "Sites", myColumnMap)
'set up the data adapter
sdaSelectedSites.SelectCommand = scmdSelectedSites
sdaSelectedSites.TableMappings.Add(myTableMap)
'open a connection
SqlConn.Open()
'fill the dataset
sdaSelectedSites.Fill(mySites)
The bold line is where the error occurs. I am just not sure why it is crapping out. I have another designer built Data Adapter that uses the same Select (different where clause) and fills that same dataset with no errors.
Me confused help please. That'l do donkey, that'l do
![[bravo] [bravo] [bravo]](/data/assets/smilies/bravo.gif)
If you are unsure of forum etiquette check here faq796-2540