当我从我的数据库中存储的数据中数据绑定我的gridview时,我看到一个小方块而不是预期的gridview结果。
我正在使用的代码:
try
{
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();
}
catch (Exception ex)
{
lblerror.Text = ex.ToString();
}
答案 0 :(得分:1)
您必须在每个参数的值中省略引号:
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);
}
还要确保打开SQL连接并将其与SQL命令绑定