Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple SQL INSERT

1 view
Skip to first unread message

Scott at Cedar Creek

unread,
Aug 17, 2006, 3:40:02 AM8/17/06
to
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.

Scott at Cedar Creek

unread,
Aug 17, 2006, 3:43:01 AM8/17/06
to

Cor Ligthert [MVP]

unread,
Aug 17, 2006, 4:10:54 AM8/17/06
to
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" <ScottatC...@discussions.microsoft.com> schreef
in bericht news:F7A911FF-3EE8-4FB3...@microsoft.com...

Cyril Gupta

unread,
Aug 17, 2006, 7:35:02 AM8/17/06
to
Hello Scott at Cedar Creek,

The following article might help you

http://cyrilgupta.com/contentprog_ado_net.htm

Regards
Cyril Gupta

You can do anything with a little bit of 'magination.
I have been programming so long, that my brain is now soft-ware.
http://www.cyrilgupta.com/blog

Edwin Knoppert

unread,
Aug 17, 2006, 11:18:11 AM8/17/06
to
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.


"Cor Ligthert [MVP]" <notmyfi...@planet.nl> schreef in bericht
news:%23cZq7Rd...@TK2MSFTNGP05.phx.gbl...

Cor Ligthert [MVP]

unread,
Aug 18, 2006, 1:24:49 AM8/18/06
to
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

Edwin Knoppert

unread,
Aug 24, 2006, 10:47:17 AM8/24/06
to
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,


"Cor Ligthert [MVP]" <notmyfi...@planet.nl> schreef in bericht

news:uRa%23yZow...@TK2MSFTNGP06.phx.gbl...

0 new messages