Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making an app .. in which there's few table the tables named Month and Expense are having 1 to many realtionship....
when ever I write this query


qry = "INSERT INTO EXPENSE values('" + tb_ID.Text + dtp_Edate.Text + "',#" + dtp_Edate.Value.ToString + "#," + tb_Amount.Text + ", '" + tb_Description.Text + "')" ... the prog shows error ,,, like sometimes ,,, that the values don't match or some times error in INSERT into ....

aaah !NEEd vb.net code.... I don't have too experience ...
Posted
Updated 13-Apr-10 9:11am
v2

1 solution

Rule one: Don't do that!
Rule two: see rule one.

Replace your query with a parameterized query. It will prevent an SQL injection attack, make your code neater, and almost certainly get rid of your problem to boot.
SqlCommand cmd = new SqlCommand("INSERT INTO Expense (ID, Date, Amount, Description) VALUES (@ID, @DT, @AM, @DS)");
cmd.AddWithValue("@ID", tb_ID.Text);
cmd.AddWithValue("@DT", dtp_Edate.Text);
cmd.AddWithValue("@AM", dtp_Edate.Value.ToString);
cmd.AddWithValue("@DS", tb_Description.Text); 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900