G
Guest
Hello,
Here is my code, first part of this code is adding a static record to an SQL
table and working fine, second part should get the data from the parameter
myDSDest and put into the same SQL table, I was thinking I would just used
dataset as the parameter for myDA.Update but it does not seem working, what
should I do?
Private Sub ELiveConnSQL(ByVal ConnStrDest As String, ByVal sqlStrDest As
String, ByVal myDSDest As DataSet)
Dim myConn As SqlConnection = New SqlConnection(ConnStrDest)
myConn.Open()
Try
Dim mySqlCommand As SqlCommand = New SqlCommand(sqlStrDest,
myConn)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(mySqlCommand)
Dim myCommandBuilder As SqlCommandBuilder = New
SqlCommandBuilder(myDA)
' Show commands
Response.Write(myCommandBuilder.GetInsertCommand().CommandText)
' /****** first part *****/
Dim myDTSrc As DataTable = New DataTable
myDA.Fill(myDTSrc)
'Use Insert
Dim myRowSrc As DataRow = myDTSrc.NewRow
myRowSrc("PtID") = "PtID"
myRowSrc("ADate") = "01/01/2005"
myRowSrc("ATime") = "12:00"
myRowSrc("PtName") = "PtName "
myDTSrc.Rows.Add(myRowSrc)
myDA.Update(myDTSrc)
myDTSrc.AcceptChanges()
' /****** second part *****/
Dim myDTDest As DataTable = New DataTable
myDTDest = myDSDest.Tables(0)
myDA.Update(myDTDest)
Catch ex As Exception
Response.Write(ex.Message)
Finally
myConn.Close()
End Try
End Sub
Thanks,
Jim.
Here is my code, first part of this code is adding a static record to an SQL
table and working fine, second part should get the data from the parameter
myDSDest and put into the same SQL table, I was thinking I would just used
dataset as the parameter for myDA.Update but it does not seem working, what
should I do?
Private Sub ELiveConnSQL(ByVal ConnStrDest As String, ByVal sqlStrDest As
String, ByVal myDSDest As DataSet)
Dim myConn As SqlConnection = New SqlConnection(ConnStrDest)
myConn.Open()
Try
Dim mySqlCommand As SqlCommand = New SqlCommand(sqlStrDest,
myConn)
Dim myDA As SqlDataAdapter = New SqlDataAdapter(mySqlCommand)
Dim myCommandBuilder As SqlCommandBuilder = New
SqlCommandBuilder(myDA)
' Show commands
Response.Write(myCommandBuilder.GetInsertCommand().CommandText)
' /****** first part *****/
Dim myDTSrc As DataTable = New DataTable
myDA.Fill(myDTSrc)
'Use Insert
Dim myRowSrc As DataRow = myDTSrc.NewRow
myRowSrc("PtID") = "PtID"
myRowSrc("ADate") = "01/01/2005"
myRowSrc("ATime") = "12:00"
myRowSrc("PtName") = "PtName "
myDTSrc.Rows.Add(myRowSrc)
myDA.Update(myDTSrc)
myDTSrc.AcceptChanges()
' /****** second part *****/
Dim myDTDest As DataTable = New DataTable
myDTDest = myDSDest.Tables(0)
myDA.Update(myDTDest)
Catch ex As Exception
Response.Write(ex.Message)
Finally
myConn.Close()
End Try
End Sub
Thanks,
Jim.