C# 数据绑定时Gridview未显示预期结果

C# 数据绑定时Gridview未显示预期结果,c#,asp.net,gridview,C#,Asp.net,Gridview,当从存储在数据库中的数据绑定gridview时,我看到一个小正方形出现,而不是预期的gridview结果 我正在使用的代码: try { DataTable dsDetalle = new DataTable("Data"); using (MySqlCommand commandSql = cn.CreateCommand()) { commandSql.Comm

当从存储在数据库中的数据绑定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();
        }

必须在每个参数的值中省略引号:

 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命令将其绑定

谢谢您的aswner,我删除了qotes,但出现了相同的错误:/调试时您尝试了什么?例如,我要做的第一件事是检查数据表,以确保按预期存储内容,如果没有按照之前的代码进行存储。感谢更正,是的,我检查数据和查询。可以从aspx页面显示GridView代码吗?也许它就在那里。。。谢谢你的帮助我发现了错误@the Muffin Man have reaseon我在查询中遇到了问题谢谢你的帮助:D