How to add a new record into the table?

N

Neuxs

I want to add a new record (i.e. new vendor) into the
table. I have tried using the Insert Command but it
doesn't insert the record into the SQL table. Or is there
any other ways to add a new record? Below are the codes
that I have typed in.

--- Codes ---

cmdInsert.CommandText = "Insert INTO " _
& "tblVendors(VendorID)" _
& "VALUES(@VendorID)"
cmdInsert.Parameters.Add("@VendorID", SqlDbType.Int, 4,
txtVendorID.Text)
 
I

Imran Koradia

Probably a dumb question - but did you call cmInsert.ExecuteNonQuery() after
adding the parameters?

Imran.
 
G

Guest

If I use ExecuteNonQuery, I would need to have a connection string to the
server right? I'm currently using the OleDbDataAdpater and
OleDbDataConnection to make my connection...
 
I

Imran Koradia

Nexus said:
If I use ExecuteNonQuery, I would need to have a connection string to the
server right? I'm currently using the OleDbDataAdpater and
OleDbDataConnection to make my connection...

Don't you already have a connection with a connection string? You shouldn't
need the OleDbDataAdapter just to insert data into the database. You just
need to call cmdInsert.ExecuteNonQuery.

Imran.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top