Click here to Skip to main content
15,902,636 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai.,

I had create the new datatable in frontend.In that datatable contains Some records., but now i want to insert that datatable values to my database table.pl give me solution for this.





Thanks & Regards.,
IdhayaRani.C<</xml>
Posted

C#
<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>
 
Share this answer
 
v2
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.
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900