how to make a selectcommand return key column information

digita

Active member
Joined
Jul 8, 2004
Messages
29
Programming Experience
1-3
I am not sure where to put this question so i have put it in the general section.

I have a problem updating my database using this code:

VB.NET:
[color=#00007f]Private[/color] moDS [color=#00007f]As[/color] DataSet
VB.NET:
[color=#00007f]Private[/color] [color=#00007f]Sub[/color] DataUpdate()
		[color=#00007f]Dim[/color] oAdapter [color=#00007f]As[/color] OleDbDataAdapter
		[color=#00007f]Dim[/color] oBuild [color=#00007f]As[/color] OleDbCommandBuilder
		[color=#00007f]Dim[/color] oDR [color=#00007f]As[/color] DataRow
		[color=#00007f]Dim[/color] strSQL [color=#00007f]As[/color] [color=#00007f]String[/color]
		[color=#00007f]Dim[/color] strID [color=#00007f]As[/color] [color=#00007f]String[/color]
		[color=#00007f]Dim[/color] strConn [color=#00007f]As[/color] [color=#00007f]String[/color]
 
[color=#007f00]		' Get Primary Key From List Box
[/color]		strID = CType(lstLeden.SelectedItem, PDSAListItemNumeric).ID.ToString()
 
[color=#007f00]		' Find Row To Update
[/color]		oDR = moDS.Tables("Gegevens").Rows.Find([color=#00007f]CInt[/color](strID))
 
[color=#007f00]		' Begin the editing process
[/color]		oDR.BeginEdit()
 
[color=#007f00]		' Load new data into row
[/color]		oDR("Voorletters") = txtVoorletters.Text
		oDR("Tussenvoegsel") = txtTussenvoegsel.Text
		oDR("Achternaam") = txtAchternaam.Text
		oDR("Aanspreeknaam") = txtAanspreeknaam.Text
		oDR("Geslacht") = txtGeslacht.Text
		oDR("Adres") = txtAdres.Text
		oDR("Postcode") = txtPostcode.Text
 
[color=#007f00]		' End the editing process
[/color]		oDR.EndEdit()
 
		Try
[color=#007f00]			' Get Connection String
[/color]			strConn = ConnectionString()
[color=#007f00]			' Build SQL String
[/color]			strSQL = "SELECT *, Achternaam + ', ' + Voorletters AS FullName FROM Gegevens"
[color=#007f00]			' Create New DataAdapter
[/color]			oAdapter = [color=#00007f]New[/color] OleDbDataAdapter(strSQL, strConn)
[color=#007f00]			' Create CommandBuild from Adapter
[/color][color=#007f00]			' This will build INSERT, UPDATE and DELETE SQL
[/color]			oBuild = [color=#00007f]New[/color] OleDbCommandBuilder(oAdapter)
 
 
[color=#007f00]			' Get Update Command Object
[/color]			oAdapter.UpdateCommand = oBuild.GetUpdateCommand()
 
[color=#007f00]			' Submit UPDATE through Adapter
[/color]			oAdapter.Update(moDS, "Gegevens")
[color=#007f00]			' Tell DataSet changes to data source are complete
[/color]			moDS.AcceptChanges()
 
[color=#007f00]			' Reload the list box
[/color]			ListLoad()
 
		Catch oException [color=#00007f]As[/color] Exception
			MessageBox.Show(oException.Message)
 
		[color=#00007f]End[/color] Try
	[color=#00007f]End[/color] [color=#00007f]Sub[/color]
That first is located just under the inherits code.

When i push the button that runs this code, it give me the error "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information"

What can I to make that SelectCommand return key column information?
 
Top Bottom