Insert query

Need4Speed

Member
Joined
Apr 4, 2007
Messages
8
Programming Experience
Beginner
Hi. Sorry about the n00by question but I'm kinda new to vb.net

I want to execute a simple 'insert' query by doing this:

VB.NET:
        con.Open()
        strSqlString = "INSERT INTO " & strTable & "(" & strColumns & ") VALUES(" & strValues & ")"
        Dim cmd As New SqlCommand(strSqlString, con)
        intNumAffected = cmd.ExecuteNonQuery()
        con.Close()

When an errors occurs I get the appropriate message like table does not exist or something like that BUT, and here's the problem, when everything's fine after having executed the code nothing changes in the database. What am I doing wrong?

Thx a lot..
 
Read the DNU link in my signature

Dont ever write SQLs like that.. It's insecure and very, very wrong. Use parameterized queries

Read the DW2 link in my signature for more information on how to do a parameterised query, and proper data access in .net 2.0 in general
 
I must agree with cjard. NEVER use concatenation in SQL, use parameters.

In addition to that, you may want to look at using the Enterprise Library from Microsoft to take advantage of the Data Access Application Block. They have already done most of the leg work for your data access code.....
 
Back
Top