Home All Groups Group Topic Archive Search About
Author
17 Aug 2006 7:40 AM
Scott at Cedar Creek
I have a SQL INSERT statement.  I'm pretty well-versed in SQL but NOT in
VB.NET / ASP.NET.  I would like to know what VB code is for inserting a new
row into a database.  I have a SQL Table established already.  I would like
to know the code required to insert a new row to that SQL Table.  I don't
have any connection strings established yet, I don't have anything.  Can you
please take pity on a poor .NET Newb and tell me what I should be doing? 
I've tried several examples and have yet to successfully insert a record.  I
think I need to know how to establish the connection, and then write (insert)
a new record to that connection.

Thanks in advance.  This stuff can be very overwhelming.

Author
17 Aug 2006 8:10 AM
Cor Ligthert [MVP]
Scott,

You only need a SQLClient.Connection,
a SQLClient.SQLCommand
and from the last an executenonquery

As pseudo sample
\\\
dim conn as new SQLClient.SQLConnection(ConnectionString)
dim cmd as new SQLClient.SQLCommand("YourSQLTransactInsertString",conn)
cmd.ExecuteNonQuery()
///

Have a look here for the connectionstring
http://www.connectionstrings.com/

I hope this helps,

Cor

Show quote
"Scott at Cedar Creek" <ScottatCedarCr***@discussions.microsoft.com> schreef
in bericht news:F7A911FF-3EE8-4FB3-98F4-898914BD3066@microsoft.com...
>I have a SQL INSERT statement.  I'm pretty well-versed in SQL but NOT in
> VB.NET / ASP.NET.  I would like to know what VB code is for inserting a
> new
> row into a database.  I have a SQL Table established already.  I would
> like
> to know the code required to insert a new row to that SQL Table.  I don't
> have any connection strings established yet, I don't have anything.  Can
> you
> please take pity on a poor .NET Newb and tell me what I should be doing?
> I've tried several examples and have yet to successfully insert a record.
> I
> think I need to know how to establish the connection, and then write
> (insert)
> a new record to that connection.
>
> Thanks in advance.  This stuff can be very overwhelming.
Author
17 Aug 2006 3:18 PM
Edwin Knoppert
And let's not forget the parameters, how i do this in OLEDB:

cmd.parameters.addwithvalue("", "hello" )
For date extend:
cmd.parameters.addwithvalue("", d.Tooadate() )

Then the INSERT or SELECT should contain ? for the field values like WHERE
ID = ? and so on.




Show quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schreef in bericht
news:%23cZq7RdwGHA.2448@TK2MSFTNGP05.phx.gbl...
> Scott,
>
> You only need a SQLClient.Connection,
> a SQLClient.SQLCommand
> and from the last an executenonquery
>
> As pseudo sample
> \\\
> dim conn as new SQLClient.SQLConnection(ConnectionString)
> dim cmd as new SQLClient.SQLCommand("YourSQLTransactInsertString",conn)
> cmd.ExecuteNonQuery()
> ///
>
> Have a look here for the connectionstring
> http://www.connectionstrings.com/
>
> I hope this helps,
>
> Cor
>
> "Scott at Cedar Creek" <ScottatCedarCr***@discussions.microsoft.com>
> schreef in bericht
> news:F7A911FF-3EE8-4FB3-98F4-898914BD3066@microsoft.com...
>>I have a SQL INSERT statement.  I'm pretty well-versed in SQL but NOT in
>> VB.NET / ASP.NET.  I would like to know what VB code is for inserting a
>> new
>> row into a database.  I have a SQL Table established already.  I would
>> like
>> to know the code required to insert a new row to that SQL Table.  I don't
>> have any connection strings established yet, I don't have anything.  Can
>> you
>> please take pity on a poor .NET Newb and tell me what I should be doing?
>> I've tried several examples and have yet to successfully insert a record.
>> I
>> think I need to know how to establish the connection, and then write
>> (insert)
>> a new record to that connection.
>>
>> Thanks in advance.  This stuff can be very overwhelming.
>
>
Author
18 Aug 2006 5:24 AM
Cor Ligthert [MVP]
Edwin,

In SQLClient this is


cmd.parameters.addwithvalue("@ToInsert", "hello" )
For date extend:
cmd.parameters.addwithvalue("@TheWhere", d.Tooadate() )

Then the INSERT or SELECT should contain @ToInsert for the field values like
WHERE
ID = @TheWhere and so on.


Cor

Show quote
>
>
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schreef in bericht
> news:%23cZq7RdwGHA.2448@TK2MSFTNGP05.phx.gbl...
>> Scott,
>>
>> You only need a SQLClient.Connection,
>> a SQLClient.SQLCommand
>> and from the last an executenonquery
>>
>> As pseudo sample
>> \\\
>> dim conn as new SQLClient.SQLConnection(ConnectionString)
>> dim cmd as new SQLClient.SQLCommand("YourSQLTransactInsertString",conn)
>> cmd.ExecuteNonQuery()
>> ///
>>
>> Have a look here for the connectionstring
>> http://www.connectionstrings.com/
>>
>> I hope this helps,
>>
>> Cor
>>
>> "Scott at Cedar Creek" <ScottatCedarCr***@discussions.microsoft.com>
>> schreef in bericht
>> news:F7A911FF-3EE8-4FB3-98F4-898914BD3066@microsoft.com...
>>>I have a SQL INSERT statement.  I'm pretty well-versed in SQL but NOT in
>>> VB.NET / ASP.NET.  I would like to know what VB code is for inserting a
>>> new
>>> row into a database.  I have a SQL Table established already.  I would
>>> like
>>> to know the code required to insert a new row to that SQL Table.  I
>>> don't
>>> have any connection strings established yet, I don't have anything.  Can
>>> you
>>> please take pity on a poor .NET Newb and tell me what I should be doing?
>>> I've tried several examples and have yet to successfully insert a
>>> record. I
>>> think I need to know how to establish the connection, and then write
>>> (insert)
>>> a new record to that connection.
>>>
>>> Thanks in advance.  This stuff can be very overwhelming.
>>
>>
>
>
Author
24 Aug 2006 2:47 PM
Edwin Knoppert
Hmm, it differs :)

At some point we will start using sqlserver as well.

Is this syntax compatible with OleDB?
Can test that of course :)

Thanks,


Show quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schreef in bericht
news:uRa%23yZowGHA.324@TK2MSFTNGP06.phx.gbl...
> Edwin,
>
> In SQLClient this is
>
>
> cmd.parameters.addwithvalue("@ToInsert", "hello" )
> For date extend:
> cmd.parameters.addwithvalue("@TheWhere", d.Tooadate() )
>
> Then the INSERT or SELECT should contain @ToInsert for the field values
> like WHERE
> ID = @TheWhere and so on.
>
>
> Cor
>
>>
>>
>>
>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schreef in bericht
>> news:%23cZq7RdwGHA.2448@TK2MSFTNGP05.phx.gbl...
>>> Scott,
>>>
>>> You only need a SQLClient.Connection,
>>> a SQLClient.SQLCommand
>>> and from the last an executenonquery
>>>
>>> As pseudo sample
>>> \\\
>>> dim conn as new SQLClient.SQLConnection(ConnectionString)
>>> dim cmd as new SQLClient.SQLCommand("YourSQLTransactInsertString",conn)
>>> cmd.ExecuteNonQuery()
>>> ///
>>>
>>> Have a look here for the connectionstring
>>> http://www.connectionstrings.com/
>>>
>>> I hope this helps,
>>>
>>> Cor
>>>
>>> "Scott at Cedar Creek" <ScottatCedarCr***@discussions.microsoft.com>
>>> schreef in bericht
>>> news:F7A911FF-3EE8-4FB3-98F4-898914BD3066@microsoft.com...
>>>>I have a SQL INSERT statement.  I'm pretty well-versed in SQL but NOT in
>>>> VB.NET / ASP.NET.  I would like to know what VB code is for inserting a
>>>> new
>>>> row into a database.  I have a SQL Table established already.  I would
>>>> like
>>>> to know the code required to insert a new row to that SQL Table.  I
>>>> don't
>>>> have any connection strings established yet, I don't have anything.
>>>> Can you
>>>> please take pity on a poor .NET Newb and tell me what I should be
>>>> doing?
>>>> I've tried several examples and have yet to successfully insert a
>>>> record. I
>>>> think I need to know how to establish the connection, and then write
>>>> (insert)
>>>> a new record to that connection.
>>>>
>>>> Thanks in advance.  This stuff can be very overwhelming.
>>>
>>>
>>
>>
>
>

AddThis Social Bookmark Button