datagridview update problem!

chetansehgal

New member
Joined
Mar 27, 2008
Messages
2
Programming Experience
Beginner
could someone please help on how to enter new values from datagridview control into my empty table in MS access?..i have configured data adapters through wizard, and have the following code for button click, for saving data. please correct it .. it must be wrong i knw! :o

VB.NET:
Expand Collapse Copy
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) handles button1.Click
    
    oleDbConnection2.Open() 
    oleDbDataAdapter2.InsertCommand = oleDbInsertCommand2 
    oleDbDataAdapter2.Update(dataSet21.Tables(0)) 
    oleDbDataAdapter2.Fill(dataSet21) 
    oleDbConnection2.Close() 
    
End Sub
or i need to code a loop for storing rows from this datagridview?...help me out!!











VB.NET:
Expand Collapse Copy
insertIntoAtmtTable.Parameters.Add("mailSubj", SqlDbType.NVarChar, 100, "Subject")
insertIntoAtmtTable.Parameters.Add("mailDateReceived", SqlDbType.NVarChar, 20, "DateReceived")
insertIntoAtmtTable.Parameters.Add("mailAtmtName", SqlDbType.NVarChar, 100, "FileName")
insertIntoAtmtTable.Parameters.Add("dateAppended", SqlDbType.DateTime, 20, "DateAppended")

This should look more like....

VB.NET:
Expand Collapse Copy
insertIntoAtmtTable.Parameters.Add("@mailSubj", SqlDbType.NVarChar, 100, "Subject")
insertIntoAtmtTable.Parameters.Add("@mailDateReceived", SqlDbType.NVarChar, 20, "DateReceived")
insertIntoAtmtTable.Parameters.Add("@mailAtmtName", SqlDbType.NVarChar, 100, "FileName")
insertIntoAtmtTable.Parameters.Add("@dateAppended", SqlDbType.DateTime, 20, "DateAppended")

But remember the first argument is the parameter name, the last argument has got to be the original name of the column in the database.

VB.NET:
Expand Collapse Copy
EtavDataAdapter.Update(EtavDataSet, "emptyemailwithattachments")

Secondly on the above line i find it's always just easier to pass the datatable you are using.

VB.NET:
Expand Collapse Copy
EtavDataAdapter.Update(EtavDataSet.Tables(0))

Or whatever the index you datatable is located at. If it's the only table in the dataset then the above code should work just fine. Also stick a try/ catch block around your update line and display the error message. it will be much more descriptive than that unhandled exception one
 
Problem with datagrid view!

can somebody please help me on this problem! with updating records in datagrid view!

also i have tried creating all this progrmaticaly...i mean not using commandbuilder. and it says " requite valid update command for passing datarow collection"...please help on this...it has been 2 days!! :eek:


Thank you in advance
 
Back
Top