且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将值从数据表值插入数据库

更新时间:2023-02-07 08:27:38

<script runat="server">
    Dim objDT As System.Data.DataTable
    Dim objDR As System.Data.DataRow

Private Sub Page_Load(s As Object, e As EventArgs)
        objDT = Session("Cart")

        dg.DataSource = objDT
        dg.DataBind()
End Sub


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
      Dim nwind As SqlConnection
        nwind = New SqlConnection("connection string info.")
        Dim custsInsCmd As SqlClient.SqlCommand
        Dim custRow As DataRow
        Dim sql As String

        custsInsCmd = nwind.CreateCommand()

        For Each custRow In objDT.Rows
            sql = "INSERT INTO rma_items (qty, mfr, part, serial, problem, order_id) VALUES ('" & custRow("Quantity") & "', '" & custRow("Manufacturer") & "', '" & custRow("Part") & "', '" & custRow("Serial") & "', '" & custRow("Problem") & "', '" & custRow("Order") & "')"
            custsInsCmd = New SqlCommand( sql, nwind )
            custsInsCmd.CommandText = sql
            nwind.Open()
            custsInsCmd.ExecuteNonQuery()
            nwind.Close()
        Next

    End Sub
</script>


假设数据表的行是dr

那么您可以获得类似的价值:-
suppose your row of your datatable is dr

then you can get value like:-
string name=dr["Customer_Name"].tostring();


像这样,您可以将所有值和易于插入到数据库中.


like this you can get all value and easile inserted to database.


选中此

http://www.xtremevbtalk.com/showthread.php?t=315988 [ ^ ]
Check this

http://www.xtremevbtalk.com/showthread.php?t=315988[^]