Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting up Data Adapter What else must I do?

Status
Not open for further replies.

Zarcom

Programmer
May 7, 2002
1,275
CA
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
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Its so funny it hurts~! hmm does that mean it is not actually funny?

STUPID STUPID STUPID... duh Can we go see the wabbits

Apparently I forgot to include the from clause for my select statment. gah!

'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 ")
Bold empty staring space
sb.Append("WHERE UNIT.CLASS = CLASS.CLASS AND (")
sb.Append("(UNIT.UNIT_ID = @unit)")


Too much sugar for me. I think I will go have some smarties. Goodnite and Happy Halloween! That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top