Hi Ivan,
Try to follow the steps below. I create the connection; I load a
dataadapter; I use it to load the dataset; then I add a new row; finally I
add a commandbuilder (you must have this or more involved insert commands to
update the back end). I'd recommend you get a good text of databases using
ado .net - ADO .Net by David Sceppa (MS Press) is about the best.
HTH,
Bernie Yaeger
Dim oconn As New SqlConnection("data source=d5z0071;initial
catalog=imc;integrated security=sspi;")
Dim ocmd As New SqlCommand("select * from histd_", oconn)
Dim oda As New SqlDataAdapter(ocmd)
Dim ods As New DataSet("History Details")
oconn.Open()
oda.Fill(ods, "History Details")
Dim r As DataRow
r = ods.Tables(0).NewRow()
r("bipad") = "98705 "
r("imcacct") = "81378-001456"
r("issuecode") = "200212"
r("posstatus") = "u"
r("draw") = 17
r("rreturn") = 2
r("net") = r("draw") - r("rreturn")
' now, to update the back end, this won't work without a commandbuilder that
references the dataadapter
Dim mcommandbuilder As SqlCommandBuilder = New SqlCommandBuilder(oda)
ods.Tables(0).Rows.Add(r)
Try
oda.Update(ods, "history details")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
oconn.Close()
"Ivan Weiss" <iv*****@optonline.net> wrote in message
news:ui**************@TK2MSFTNGP09.phx.gbl...
Another question for the whizzes out there. I have the following code
in a database class:
Public Sub insertData(ByVal argInsertSql As String, ByVal argTable As
String)
Dim myConnection As New OleDbConnection(dbConnString)
Dim strSelectSql As String = "SELECT * FROM " & argTable
Dim myDataAdapter As New OleDbDataAdapter(strSelectSql,
myConnection)
Dim myDataSet As New DataSet()
Dim myDataTable As DataTable()
Dim myDataRow As DataRow()
Try
myConnection.Open()
myDataAdapter.Fill(myDataSet, argTable)
myDataTable = myDataSet.Tables(argTable)
myDataRow = myDataTable.newrow
Catch
DisplayErrorMessage("clsDatabase:insertData")
End Try
End Sub
The myDataTable = myDataSet.Tables(argTable) AND
the myDataRow = myDataTable.newrow
are both generating errors. Saying cant convert data table to
1-dimensional array of type datatable. I am trying to learn how to
update a database via ADO.Net directly from an online book I have and
there example isn't working.
What am I doing wrong?
-Ivan
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!