better way to write insert into

d2005

Active member
Joined
Aug 31, 2005
Messages
37
Location
ireland
Programming Experience
Beginner
hi my code shown below, igves an error of an unequal number of arguments, but i count 11 on each. confusing.

1)is there a better way to write insert statement, please give example.
2)please give an example of insert without textbox ie now() for date and time,

thanks in advance.
im only a begginer.

VB.NET:
Dim sqlInsertuser As New SqlCommand("INSERT INTO tb_user(c_orig_addr,c_user_fname,c_user_sname,c_username_login,c_user_password,c_user_house,c_user_street,c_user_town,c_user_postcode,c_user_tel_alt,c_user_email) VALUES('" & txt_mobile.Text & "','" & txt_fname.Text & "''" & txt_sname.Text & "','" & txt_username.Text & "','" & txt_password.Text & "','" & txt_house.Text & "','" & txt_street.Text & "','" & txt_town.Text & "','" & txt_post.Text & "','" & txt_tel.Text & "','" & txt_email.Text & "');", oSQLConn)

'sqlInsertuser.Connection.Open() 

sqlInsertuser.ExecuteNonQuery()

oSQLConn.Close()
 
Between fname and sname, you missed a comma:

txt_fname.Text & "','" & txt_sname.Text

1) YEs, there is, using stored procedures (if SQL Server) or parameterized queries (if Access). Familiar with either one?

2) Not sure what you meant by this.

-tg
 
Use a Stored Procedure or do the following:


Dim sqlInsert as string
sqlInsert = "Insert Statement here"

Dim sqlComm as new sqlCommand(sqlInsert)
This is just to keep you sane
 
Back
Top