-
Urgent DataAdapter
When i create my data adapter using the wizard it does not create the update and delete, this has thrown me
Last edited by michaelw; 08-02-2005 at 6:17 AM.
-
be more clear in your question as i am unable to figure out ur problem.
if u are using sqlclient.sqlcommandbuilder then u must have a primary key in any of the field of your database.
-
I am using the wizard to create a oledbdataadapter. i can fill the dataset but when i change a field value and update it brings back an error. When i created the adapter it created all but the update and delete statements.
My code is
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DataSet31.Clear()
OleDbDataAdapter1.Fill(DataSet31)
DataGrid1.DataSource = DataSet31
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OleDbDataAdapter1.Update(DataSet31)
MessageBox.Show("Datbase Updated")
EndSub
-
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OleDbDataAdapter1.Update(DataSet31)
MessageBox.Show("Datbase Updated")
EndSub
this was your code
right one is : OleDbDataAdapter1.Update(DataSet31,"<tablename>")
-
Where you put table name is that the table in sql server or the datagrid name and do you have to put it in the <>??
-
right one is : OleDbDataAdapter1.Update(DataSet31,"<tablename>")
no u dont have to put "<>"
just put tablename in quotes.
tablename will the name of the table of your database to which you are sending the updating values.
-
This seems to have done somthing but not update the table, it does not crash anymore but it does not update the table either and i cant figure out why? any suggestions my code now is>
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DataSet31.Clear()
OleDbDataAdapter1.Fill(DataSet31)
DataGrid1.DataSource = DataSet31
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OleDbDataAdapter1.Update(DataSet31)
MessageBox.Show("Datbase Updated")
EndSub
PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
SqlDataAdapter1.Fill(DataSet11)
DataGrid2.DataSource = (DataSet11)
EndSub
PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim objcommandbuilder AsNew SqlClient.SqlCommandBuilder
OleDbDataAdapter1.Update(DataSet31, "jobs")
MessageBox.Show("database Updated")
EndSub
-
here goes the complete code
suppose u have two fields in table: name and s_no
dim objconnection as new sqlclient.sqlconnection("<connection string>")
dim objadapter as new sqlclient.sqldataadapter("select * from <tablename>",objconnection)
dim objadatset as new dataset()
objadapter.fill(objdataset,"<tablename">)
dim objbuilder as new sqlclient.sqlcommandbuilder(objadapter)
now suppose we have to find s_no and change the name field.
dim objdataview as new dataview(objdataset.tables(0))
dim inum as integer
objdataview.sort="s_no"
inum=objdataview.find(<source s_no>)
objdataview.tables(0).row(inum).item("name")=updat ed name is written here
objadapter.update(objdataset,"<tablename>")
Last edited by nakracreative; 08-02-2005 at 9:12 AM.
-
u are dircetly using the update mehod of dataadapter ( OK no problem i understand this)
but nowhere have u used the update query of sql ( sorry do not understand where i would place the SQL to relate to the coloums and values)
and there are also no paramaters collection. ( this is new to me)
I have read so many articales on dataset updates and although they gave me the basics, i stll cant get the update working.
thanks for your help
Michael
-
here goes the complete code
suppose u have two fields in table: name and s_no
dim objconnection as new sqlclient.sqlconnection("<connection string>")
dim objadapter as new sqlclient.sqldataadapter("select * from <tablename>",objconnection)
dim objadatset as new dataset()
objadapter.fill(objdataset,"<tablename">)
dim objbuilder as new sqlclient.sqlcommandbuilder(objadapter)
now suppose we have to find s_no and change the name field.
dim objdataview as new dataview(objdataset.tables(0))
dim inum as integer
objdataview.sort="s_no"
inum=objdataview.find(<source s_no>)
objdataview.tables(0).row(inum).item("name")=updat ed name is written here
objadapter.update(objdataset,"<tablename>")
-
Ok this is what i come up with thanks for the help
I am having a problem with the
objadapter
objdataview
inum
are telling me that declartions are needed??
I thought this would be done when i dim them??
Dim objconnection asNew SqlClient.SqlConnection("Initial catalog=testbooking;" & "Data Source=(Install_BDC); Integrated Security=SSPI
Dim objadapter AsNew SqlClient.SqlDataAdapter("Select Urn, invoiceno FROM jobs", objconnection)
Dim objadataset AsNew DataSet
objadapter.fill (objadapter, "Jobs")
Dim objbuilder AsNew SqlClient.SqlCommandBuilder(objadapter)
Dim objdataview AsNew DataView(objadataset.Tables(0))
Dim inum AsInteger
objdataview.sort="Urn"
inum = objdataview.find(<source s_no>)
objdataview.tables(0).ow(inum).item("URN")=TEST
objadapter.update(objdataset, "Jobs")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks