在查询1和2中,文本框中的文本都插入到数据库中.这里参数化查询的意义是什么?
1.> -------------
SqlCommand cmd = new SqlCommand("INSERT INTO dbo.Cars " +"VALUES(@TagNbr);" , conn);
cmd.Parameters.Add("@TagNbr", SqlDbType.Int);
cmd.Parameters["@TagNbr"].Value = txtTagNumber.Text;
Run Code Online (Sandbox Code Playgroud)
2.> --------------
int tagnumber = txtTagNumber.Text.ToInt16(); /* EDITED */
INSERT into Cars values(tagnumber.Text); /* then is it the same? */
Run Code Online (Sandbox Code Playgroud)
此外,在这里我将使用正则表达式验证来停止插入非法字符.