[英]show data grid view
當我按下按鈕“agregar”時,我在顯示網格視圖的數據時遇到問題:
它顯示一個小方塊,不顯示任何數據。
cn.Open();
MySqlCommand cm = cn.CreateCommand();
cm.CommandType = CommandType.Text;
cm.CommandText = "select * from detalle where iddetalle= '" + txt_boleta.Text + "'and idlocal='" + txtlocal.Text + "'";
cm.ExecuteNonQuery();
MySqlDataAdapter da = new MySqlDataAdapter(cm);
DataSet ds = new DataSet();
da.Fill(ds,"data");
GridView1.DataSource = ds.Tables["data"];
GridView1.DataBind();
您有您的查詢的幾個問題,一個快速的解決方法是通過在之間給人一種空間"'
,並and
在"'and
,通過這個你是通過注射開門黑客,所以,更好的選擇是使用參數化查詢。 還有一些建議:
總之綁定網格的代碼應該是這樣的:
DataTable dsDetalle=new DataTable("Data");
using (MySqlCommand commandSql = cn.CreateCommand())
{
commandSql.CommandType = CommandType.Text;
commandSql.CommandText = "select * from detalle where iddetalle=@iddetalle and idlocal=@idlocal";
commandSql.Parameters.AddWithValue("@iddetalle", "txt_boleta.Text");
commandSql.Parameters.AddWithValue("@idlocal", "txtlocal.Text");
MySqlDataAdapter sqlAdapter = new MySqlDataAdapter(commandSql);
sqlAdapter.Fill(dsDetalle);
}
GridView1.DataSource = dsDetalle;
GridView1.DataBind();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.