add records in Database from Datatable and Dataset without insert command

  • Try

    Dim ds As DataSet = New DataSet()
    Dim MyDataTable As New DataTable("temporary_TableName") 'Must Specify Table name otherwise dt return table with Name Table1

    ' Dim MyDataTable As New DataTable


    ds.Tables.Add(MyDataTable)

    'Dataset require Table name beacuse it can consist of multiple tables so Tablename must specify
    'At all places mapp datatable name which will return datatable object


    Dim LoadAdapt As New SqlDataAdapter("SELECT * From aa", con) ' Get Records from Database
    con.Open()
    LoadAdapt.FillSchema(ds, SchemaType.Source, "temporary_TableName") ' Fill Records into Datatable from Dataset
    LoadAdapt.Fill(ds, "temporary_TableName")

    Dim cbSQLCOMB As New SqlCommandBuilder(LoadAdapt) ' Command Builder works here as a insert command
    Dim dr As DataRow

    dr = MyDataTable.NewRow()


    dr("a") = TextBox1.Text '' Column Name to where put Data
    dr("b") = TextBox2.Text

    MyDataTable.Rows.Add(dr)
    LoadAdapt.Update(ds, "temporary_TableName") ' Map Temporary Table to database

    da.Fill(dt)
    DataGridView1.DataSource = dt


    con.Close()

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week