DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 30 Jul 2007 15:56:44 -0500,    posted on: microsoft.public.dotnet.languages.vb.data        back       

Thread Index
  1    fniles
          2    Cor Ligthert[MVP]
          3    Cor Ligthert[MVP]
                 4    fniles
                 5    fniles
                        6    Cor Ligthert[MVP]
                        7    Cor Ligthert[MVP]
                 8    fniles
                 9    fniles
                        10    Cor Ligthert[MVP]
                        11    Cor Ligthert[MVP]
                        12    fniles
                        13    fniles
                        14    Cor Ligthert[MVP]
                        15    Cor Ligthert[MVP]
          16    Armin Zingler
          17    Armin Zingler
                 18    Cor Ligthert[MVP]
                 19    Cor Ligthert[MVP]
                 20    Armin Zingler
                 21    Armin Zingler


Addnew in VB.NET ?   
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
Date:Mon, 30 Jul 2007 15:56:44 -0500   Author:  

Re: Addnew in VB.NET ?   
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"  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
> 
Date:Tue, 31 Jul 2007 00:13:07 +0200   Author:  

Re: Addnew in VB.NET ?   
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"  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
> 
Date:Tue, 31 Jul 2007 00:13:07 +0200   Author:  

Re: Addnew in VB.NET ?   
"fniles"  schrieb

> 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
> 
> 


http://msdn2.microsoft.com/en-us/library/e80y5yhx.aspx



Armin
Date:Mon, 30 Jul 2007 23:13:54 +0200   Author:  

Re: Addnew in VB.NET ?   
"fniles"  schrieb

> 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
> 
> 


http://msdn2.microsoft.com/en-us/library/e80y5yhx.aspx



Armin
Date:Mon, 30 Jul 2007 23:13:54 +0200   Author:  

Re: Addnew in VB.NET ?   
Armin,

I did not see your message yet when I was sending mine.

Cor

"Armin Zingler"  schreef in bericht 
news:eNcFgwv0HHA.5380@TK2MSFTNGP04.phx.gbl...

> "fniles"  schrieb
>> 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
>>
>>
>
> http://msdn2.microsoft.com/en-us/library/e80y5yhx.aspx
>
>
>
> Armin 
Date:Tue, 31 Jul 2007 10:51:10 +0200   Author:  

Re: Addnew in VB.NET ?   
Armin,

I did not see your message yet when I was sending mine.

Cor

"Armin Zingler"  schreef in bericht 
news:eNcFgwv0HHA.5380@TK2MSFTNGP04.phx.gbl...

> "fniles"  schrieb
>> 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
>>
>>
>
> http://msdn2.microsoft.com/en-us/library/e80y5yhx.aspx
>
>
>
> Armin 
Date:Tue, 31 Jul 2007 10:51:10 +0200   Author:  

Re: Addnew in VB.NET ?   
"Cor Ligthert[MVP]"  schrieb

> Armin,
> 
> I did not see your message yet when I was sending mine.


Sry Cor, my fault, forgot mine in the outbox.


Armin
Date:Tue, 31 Jul 2007 12:26:46 +0200   Author:  

Re: Addnew in VB.NET ?   
"Cor Ligthert[MVP]"  schrieb

> Armin,
> 
> I did not see your message yet when I was sending mine.


Sry Cor, my fault, forgot mine in the outbox.


Armin
Date:Tue, 31 Jul 2007 12:26:46 +0200   Author:  

Re: Addnew in VB.NET ?   
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]"  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"  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
>>
> 
Date:Tue, 31 Jul 2007 10:10:53 -0500   Author:  

Re: Addnew in VB.NET ?   
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]"  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"  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
>>
> 
Date:Tue, 31 Jul 2007 10:10:53 -0500   Author:  

Re: Addnew in VB.NET ?   
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"  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]"  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"  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
>>>
>>
>
> 
Date:Tue, 31 Jul 2007 17:47:44 +0200   Author:  

Re: Addnew in VB.NET ?   
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"  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]"  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"  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
>>>
>>
>
> 
Date:Tue, 31 Jul 2007 17:47:44 +0200   Author:  

Re: Addnew in VB.NET ?   
Thank you, that works.
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
Dim m_cmdBuilderSQL As SqlClient.SqlCommandBuilder

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_cmdBuilderSQL = New SqlClient.SqlCommandBuilder(m_daSQL)
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_cmdBuilderSQL.GetInsertCommand()
m_daSQL.Update(m_dsSQL)

I am wondering which one is faster, using the code above (with 
sqlcommandbuilder) or use ExecuteNonQuery method of the SQLCommand like the 
following:
Dim m_cmdSQL As SqlClient.SqlCommand

sSQL = "insert into myTable (colA) values (sValue)"
m_cmdSQL = New SqlClient.SqlCommand
With m_cmdSQL
 .Connection = adoCon
 .CommandText = sSQL
End With
m_cmdSQL.ExecuteNonQuery()

"Cor Ligthert[MVP]"  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"  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]"  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"  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
>>>>
>>>
>>
>>
> 
Date:Tue, 31 Jul 2007 15:30:56 -0500   Author:  

Re: Addnew in VB.NET ?   
Thank you, that works.
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
Dim m_cmdBuilderSQL As SqlClient.SqlCommandBuilder

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_cmdBuilderSQL = New SqlClient.SqlCommandBuilder(m_daSQL)
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_cmdBuilderSQL.GetInsertCommand()
m_daSQL.Update(m_dsSQL)

I am wondering which one is faster, using the code above (with 
sqlcommandbuilder) or use ExecuteNonQuery method of the SQLCommand like the 
following:
Dim m_cmdSQL As SqlClient.SqlCommand

sSQL = "insert into myTable (colA) values (sValue)"
m_cmdSQL = New SqlClient.SqlCommand
With m_cmdSQL
 .Connection = adoCon
 .CommandText = sSQL
End With
m_cmdSQL.ExecuteNonQuery()

"Cor Ligthert[MVP]"  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"  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]"  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"  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
>>>>
>>>
>>
>>
> 
Date:Tue, 31 Jul 2007 15:30:56 -0500   Author:  

Re: Addnew in VB.NET ?   

>
> I am wondering which one is faster, using the code above (with 
> sqlcommandbuilder) or use ExecuteNonQuery method of the SQLCommand like 
> the following:


This will in my idea probebly only be showable when you do this 10000 times 
and than only as a part of a millisecond.

In dataprocessing there are however mostly better options to take a look at 
speed which can than better first be investigated. (As there is a need for 
it, keep in mind the 20:80 rule for that)

Mostly something as 20% of your code is doing 80% of the job.

Cor
Date:Wed, 1 Aug 2007 01:34:47 +0200   Author:  

Re: Addnew in VB.NET ?   

>
> I am wondering which one is faster, using the code above (with 
> sqlcommandbuilder) or use ExecuteNonQuery method of the SQLCommand like 
> the following:


This will in my idea probebly only be showable when you do this 10000 times 
and than only as a part of a millisecond.

In dataprocessing there are however mostly better options to take a look at 
speed which can than better first be investigated. (As there is a need for 
it, keep in mind the 20:80 rule for that)

Mostly something as 20% of your code is doing 80% of the job.

Cor
Date:Wed, 1 Aug 2007 01:34:47 +0200   Author:  

Re: Addnew in VB.NET ?   
But, with the sqlcommandbuilder, you need to select the table first, add the 
row then update it, instead of just executing an "INSERT INTO" command using 
ExecuteNonQuery.
You don't think the ExecuteNonQuery is faster ?

Thanks

"Cor Ligthert[MVP]"  wrote in message 
news:8640D073-48A8-44A9-BDC5-025C32686863@microsoft.com...

> >
>> I am wondering which one is faster, using the code above (with 
>> sqlcommandbuilder) or use ExecuteNonQuery method of the SQLCommand like 
>> the following:
>
> This will in my idea probebly only be showable when you do this 10000 
> times and than only as a part of a millisecond.
>
> In dataprocessing there are however mostly better options to take a look 
> at speed which can than better first be investigated. (As there is a need 
> for it, keep in mind the 20:80 rule for that)
>
> Mostly something as 20% of your code is doing 80% of the job.
>
> Cor 
Date:Wed, 1 Aug 2007 11:11:29 -0500   Author:  

Re: Addnew in VB.NET ?   
But, with the sqlcommandbuilder, you need to select the table first, add the 
row then update it, instead of just executing an "INSERT INTO" command using 
ExecuteNonQuery.
You don't think the ExecuteNonQuery is faster ?

Thanks

"Cor Ligthert[MVP]"  wrote in message 
news:8640D073-48A8-44A9-BDC5-025C32686863@microsoft.com...

> >
>> I am wondering which one is faster, using the code above (with 
>> sqlcommandbuilder) or use ExecuteNonQuery method of the SQLCommand like 
>> the following:
>
> This will in my idea probebly only be showable when you do this 10000 
> times and than only as a part of a millisecond.
>
> In dataprocessing there are however mostly better options to take a look 
> at speed which can than better first be investigated. (As there is a need 
> for it, keep in mind the 20:80 rule for that)
>
> Mostly something as 20% of your code is doing 80% of the job.
>
> Cor 
Date:Wed, 1 Aug 2007 11:11:29 -0500   Author:  

Re: Addnew in VB.NET ?   

> But, with the sqlcommandbuilder, you need to select the table first, add 
> the row then update it, instead of just executing an "INSERT INTO" command 
> using ExecuteNonQuery.
> You don't think the ExecuteNonQuery is faster ?
>

Picoseconds, in my eyes not important enough to take any investigation or 
whatever too.

This part of the job in the updating takes on the client versus the netwerk 
aand server let's say 1:100 of the time, if you want speed, than look at the 
hardware how you can improve it.

Just my opinion,

Cor
Date:Fri, 3 Aug 2007 03:05:32 +0200   Author:  

Re: Addnew in VB.NET ?   

> But, with the sqlcommandbuilder, you need to select the table first, add 
> the row then update it, instead of just executing an "INSERT INTO" command 
> using ExecuteNonQuery.
> You don't think the ExecuteNonQuery is faster ?
>

Picoseconds, in my eyes not important enough to take any investigation or 
whatever too.

This part of the job in the updating takes on the client versus the netwerk 
aand server let's say 1:100 of the time, if you want speed, than look at the 
hardware how you can improve it.

Just my opinion,

Cor
Date:Fri, 3 Aug 2007 03:05:32 +0200   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us