perini14
August 7th, 2002, 04:01 AM
How to change insert command generated by oledbcommandbuilder??
For ex. I have this code that creates data adapter and commands:
Dim daTrening as OleDbDataAdapter
Dim cbTrening as OleDbCommandBuilder
daTrening = New OleDbDataAdapter("select * from trening where clan_id=" & clanid, Conn_s)
daTrening.TableMappings.Add("Table", "Trening")
daTrening.Fill(data_set)
cbTrening = New OleDbCommandBuilder(daTrening)
By executing this msgbox:
MsgBox(cbTrening.GetInsertCommand.CommandText)
I found out that commandbuilder builds this insert command:
INSERT INTO `trening`( `clan_id` , `mjesec` , `brojtreninga` , `prisustvovao` ) VALUES ( ? , ? , ? , ? )"
What I realy need is to set the first parameter (for 'clan_id') manualy, in code. But, command builder doesn't have a "set" statement to do that, or a "set" for changing the insert command - I can only read what he generated.
Then I tryed this aproach:
daTrening.InsertCommand=cbTrening.GetInsertCommand
Here I have access to data adapters "parameters" property, I can read it,so teoreticaly, I could change the value of the first parameter - but, after doing that, nothing happens, the data adapter seams to work with original commands generated by command builder.
At last, after command builder builds its command, I've tryed to set the data adapters insert command manualy, by declaring separate oledbcommand object and attaching it to the insertcommand property of data adapter.
And that worked! But, to do that I have to write to much code, cca 10 lines - I can't believe that there is not a easyer way to just change the first parameter value of the insert command generated by command builder !!!
Help !
For ex. I have this code that creates data adapter and commands:
Dim daTrening as OleDbDataAdapter
Dim cbTrening as OleDbCommandBuilder
daTrening = New OleDbDataAdapter("select * from trening where clan_id=" & clanid, Conn_s)
daTrening.TableMappings.Add("Table", "Trening")
daTrening.Fill(data_set)
cbTrening = New OleDbCommandBuilder(daTrening)
By executing this msgbox:
MsgBox(cbTrening.GetInsertCommand.CommandText)
I found out that commandbuilder builds this insert command:
INSERT INTO `trening`( `clan_id` , `mjesec` , `brojtreninga` , `prisustvovao` ) VALUES ( ? , ? , ? , ? )"
What I realy need is to set the first parameter (for 'clan_id') manualy, in code. But, command builder doesn't have a "set" statement to do that, or a "set" for changing the insert command - I can only read what he generated.
Then I tryed this aproach:
daTrening.InsertCommand=cbTrening.GetInsertCommand
Here I have access to data adapters "parameters" property, I can read it,so teoreticaly, I could change the value of the first parameter - but, after doing that, nothing happens, the data adapter seams to work with original commands generated by command builder.
At last, after command builder builds its command, I've tryed to set the data adapters insert command manualy, by declaring separate oledbcommand object and attaching it to the insertcommand property of data adapter.
And that worked! But, to do that I have to write to much code, cca 10 lines - I can't believe that there is not a easyer way to just change the first parameter value of the insert command generated by command builder !!!
Help !