Thank you, that works.
"Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
news:0958E0AE-C135-407C-8B67-8ADE8EDF72A2@microsoft.com...
> fniles,
>
> In my idea it is for this kind of simple updates the easiest and best to
> use the commandbuilder.
>
>
http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx >
> Cor
>
> "fniles" <fniles@pfmail.com> schreef in bericht
> news:%23lqQEU40HHA.4184@TK2MSFTNGP06.phx.gbl...
>> Thank you.
>> When I tried it, when trying to update the database, it gave me the error
>> "Update requires a valid InsertCommand when passed DataRow collection
>> with new rows."
>> This is what I do:
>> Dim m_daSQL As SqlClient.SqlDataAdapter
>> Dim m_cmdSQL As SqlClient.SqlCommand
>> Dim m_dsSQL As DataSet
>> Dim m_row As System.Data.DataRow
>>
>> m_cmdSQL = New SqlClient.SqlCommand
>> With m_cmdSQL
>> .Connection = adoCon
>> .CommandText = "select * from myTable"
>> End With
>> m_daSQL = New SqlClient.SqlDataAdapter
>> m_dsSQL = New DataSet
>> m_daSQL.SelectCommand = m_cmdSQL
>> m_daSQL.Fill(m_dsSQL)
>> m_row = m_dsSQL.Tables(0).NewRow
>> m_row("colA") = sValue
>> m_dsSQL.Tables(0).Rows.Add(m_row)
>> m_daSQL.Update(m_dsSQL) --> error "Update requires a valid InsertCommand
>> when passed DataRow collection with new rows."
>>
>> Do I have to create an Insert Command in the SQLDataAdapter like so :
>> m_daSQL.InsertCommand = New SqlClient.SqlCommand("INSERT INTO myTable
>> (ColA) VALUES(?)", adoCon)
>> myParm = m_daSQL.InsertCommand.Parameters.Add("@colA", SqlDbType.VarChar,
>> 15, "ColA")
>> ?
>>
>> Thanks.
>>
>> "Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
>> news:D308C651-8B6C-4624-B32D-CA4FCC4B399A@microsoft.com...
>>> fniles,
>>>
>>> Almost the same as I have answered this 4 hours ago to JNTP.
>>>
>>> To add a newrow to a table you can use in your case the newrow method.
>>>
http://msdn2.microsoft.com/en-us/library/system.data.datatable.newrow.aspx >>>
>>> (a sample how to do it is at this page at the bottom of the VB.Net
>>> part).
>>>
>>> Beside that exist too the dataview.newrow.
>>>
http://msdn2.microsoft.com/en-us/library/system.data.dataview.addnew.aspx >>>
>>>
>>> Cor
>>>
>>>
>>> "fniles" <fniles@pfmail.com> schreef in bericht
>>> news:%23g$ppwu0HHA.3916@TK2MSFTNGP02.phx.gbl...
>>>> In VB6 to add a new record in a recorset, you can use the Addnew
>>>> method, then set each column's value, then call the Update method.
>>>> How can I do this in VB.NET ?
>>>> Thank you.
>>>>
>>>> VB6:
>>>> Private m_rs As new ADODB.Recordset
>>>>
>>>> m_rs.Open "SELECT * FROM myTable", adoCon, adOpenKeyset,
>>>> adLockOptimistic
>>>> with m_rs
>>>> .AddNew
>>>> .Fields("ip") = AccountIP & " " ' x.Address
>>>> .Fields("account") = Account & " " 'Left$(x.Key, 5)
>>>> .Fields("DATEtime") = Now & " "
>>>> .Fields("name") = userver & " "
>>>> .Update
>>>> end with
>>>>
>>>
>>
>>
>