数据列表where子句

时间:2014-02-01 23:08:05

标签: asp.net

我正在使用数据列表显示视频,但我正在尝试使用where clasue ...其中名称等于wrd.mp4,我收到以下错误,

$ exception {“无法绑定多部分标识符\”wrd.mp4 \“。}} System.Exception {System.Data.SqlClient.SqlException}

private void BindGrid()
{
    string strConnString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ConnectionString;
    using (SqlConnection con = new SqlConnection(strConnString))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "select Id, Name from tblFiles where Name=wrd.mp4";
            cmd.Connection = con;
            con.Open();
            DataList1.DataSource = cmd.ExecuteReader();
            DataList1.DataBind();
            con.Close();
        }
    }
}

    }

1 个答案:

答案 0 :(得分:0)

您需要使用引号:

cmd.CommandText = "select Id, Name from tblFiles where Name='wrd.mp4'";