Q: what is missing with this code?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top