Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inset into SQLServer without a select

Status
Not open for further replies.

IAMQSC

Programmer
Jan 15, 2002
3
US
Is it possible to or does it make sense to insert a row into a database with vb.net without going through the extra step of first doing a select on the database for a dataadapter. I come from the recordsets in VB6 and it was normal to insert into a database with out first doing a select on the database. I am also attempting to add a value to an SQL datetime field and return the identity key value. Is it better to just do this with a stored procedure?
 
As a programmer you should be aware that everything is possible. Especially in you case.
:)
If I understand your goal, you should use SqlCommand object to execute Insert action on the database. You should use a stored procedure in which you should return a @@identity value for inserted row.
 
here is some code to help you along the way

Code:
Dim comTemp As SqlCommand
Dim contemp As New SqlConnection
Dim intresult As Integer

contemp.connectionstring = ...
contemp.open()
comTemp = New SqlCommand("SQL", contemp)
intResult = comTemp.ExecuteNonQuery
contemp.Close()
comTemp = Nothing
contemp = Nothing

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Investigate the SQL "UPDATE" and "INSERT" commands.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top