When you concatenate strings, you cause problems because SQL receives commands like: SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command: SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands: SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT DROP TABLE MyTable; A perfectly valid "delete the table" command And everything else is a comment. So it does: selects any matching rows, deletes the table from the DB, and ignores anything else. So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
Để nó hiểu kiểu int thì bạn bỏ nháy ' Mã: string strSQL = "select from Nha where ID=" + id;Bạn đã lấy thông tin dựa vào id, sao ở dưới lại kiểm tra một lần nữa làm gì vậy ?
Để nó hiểu kiểu int thì bạn bỏ nháy ' Mã: string strSQL = "select from Nha where ID=" + id;Bạn đã lấy thông tin dựa vào id, sao ở dưới lại kiểm tra một lần nữa làm gì vậy ? "Bạn đã lấy thông tin dựa vào id, sao ở dưới lại kiểm tra một lần nữa làm gì vậy ?" là lúc đầu mình chưa có để dk where" mình đã làm được cảm ơn bạn nhìu -
lỗi Data type mismatch in criteria expression trong luc select dữ liệucác bạn giúp mình với code lấy dữ liệu của mình dựa trên IDMã: public static DataTable SelectAllNha(int id) > { > DataTable dt = null; > // > tao ra cau truy van select > string strSQL = "select * from Nha where ID='"+id+"' ";// chổ này khi mình để dk where vào thì nó sẽ báo lỗi như hình > // > co lop ho truc thuc thi cau truy nay > tra gia tri >DataProvider dp = new DataProvider(); > dt = dp.ExecuteQuery(strSQL); > for (int i = 0; i < dt.Rows.Count; i++) > if (id == int.Parse(dt.Rows[i]["ID"].ToString())) > return dt; > return dt; > } Mã: public DataTable ExecuteQuery(string _strSQL) > { > DataTable dt = new DataTable(); > OleDbDataAdapter adapter = new OleDbDataAdapter(_strSQL, strConnect); > adapter.Fill(dt); > return dt; > } -
Để nó hiểu kiểu int thì bạn bỏ nháy ' Mã: string strSQL = "select * from Nha where ID=" + id; Bạn đã lấy thông tin dựa vào id, sao ở dưới lại kiểm tra một lần nữa làm gì vậy ? cám ơn bạn rất nhiều! chỉ có mỗi dấu nháy đơn hay kép mà ngồi mò debug cả ngày không biết vì đâu, may mà đọc được bài của bạn [IMG]images/smilies/smile.png[/IMG] thanks ---
Quyền viết bài
Nội quy - Quy định |