--------------------------------------------------------------------------------

Hello

I am Using Vb.Net 2005 And Sql2005

See This

Dim RsSave as new adodb.recordset
RsSave.open "Select * From Table Where 1=2 ",Con,CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic
 
con.Begintrans
 
RsSave.AddNew
RsSave.Fields(0).Value = textbox1.text
RsSave.Fields(1).Value = textbox2.text
RsSave.Fields(2).Value = textbox3.text
RsSave.Update
 
Con.Commitrans

This Just eg for saving to databse using Adodb connection And Recordset

My Question is Hw to Save like this using Oledb Connection And Dataset

I will Try for that but not getting


--------------------------------------------------------------------------------

Faisal

you will need dataAdapter and dataset
by using dataset you can update the value of any cell in database

Me.DataSet11.Tables("Table_Name").Rows(0).Item(1) = TextBox1.Text

this will not update your databse , to change it you must write

Me.OleDbDataAdapter1.Update(Me.DataSet11)

inserting new row is like updating, you first add new row into dataset then update dataAdapter

Dim Row As DataRow
        Row = Me.DataSet11.Tables("Table_Name").NewRow()

        Row.Item(0) = textbox1.text 
        .....       
        Me.DataSet11.Tables("table_name").Rows.Add(Row)

        Me.OleDbDataAdapter1.Update(DataSet11,table_name)

Hello

Thanx For reply

I try that By Following code

Public Sub Saving(ByVal Table As String, ByVal Fields As String, ByVal Values As String)
        Dim DsS As New DataSet
        Dim cmd1 As New OleDbCommand(" Select * From " & Table & " Where 1 =2 ", Con)
        Dap = New OleDbDataAdapter(cmd1)
        Dap.Fill(DsS, Table)
        Dim DrS As DataRow = DsS.Tables(Table).NewRow
        Dim F = Split(Fields, ",")
        Dim V = Split(Values, ",")
        For i As Integer = 0 To UBound(F)
            DrS.Item(F(i)) = V(i)
        Next
        DsS.Tables(Table).Rows.Add(DrS)
        Dap.Update(DsS, Table)
        MsgBox("ADDED")

    End Sub

But Error is coming When Update
Please clear me

Faisal

what are the errors ?

Hello

I am Attachin error

the error
"update requires a valid insertCommand when passed DataRW collection with new rows"
tells you that when you add new row using

Dap.Update(DsS, Table)

, you must set insertCommand's properties

The update is performed on a by-row basis. For every inserted, modified, and deleted row, the Update method determines the type of change that has been performed on it (Insert, Update or Delete). Depending on the type of change, the Insert, Update, or Delete command template executes to propagate the modified row to the data source. When an application calls the Update method, the DataAdapter examines the RowState property, and executes the required INSERT, UPDATE, or DELETE statements iteratively for each row, based on the order of the indexes configured in the DataSet

the source
also see this link
so change the Rowstate to Unchanged by
writing

DsS.Tables(Table).Rows.Add(DrS)
the DrS.AcceptChanges()

I hope that will help you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.