Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# microsoftvisualstudio中的SQL查询_C#_Sql Server - Fatal编程技术网

C# microsoftvisualstudio中的SQL查询

C# microsoftvisualstudio中的SQL查询,c#,sql-server,C#,Sql Server,在上面的代码中,where子句在select查询中不起作用 public Availableopt(ref SqlConnection nsc, String ac, String nonac, String sit1, String sleep1, String fromopt, String toopt) { InitializeComponent(); // String s = "select * from Available where From =

在上面的代码中,where子句在select查询中不起作用

public Availableopt(ref SqlConnection nsc, String ac, String nonac, String sit1, String sleep1, String fromopt, String toopt)
{
        InitializeComponent();

        // String s = "select * from Available where From = @fromopt ";
        SqlCommand ncd = new SqlCommand("select * from Available", nsc);
        SqlDataAdapter sdan1 = new SqlDataAdapter();
        sdan1.SelectCommand = ncd;

        DataTable db = new DataTable();
        sdan1.Fill(db);

        BindingSource bs = new BindingSource();
        bs.DataSource = db;
        grid.DataSource = bs;

        sdan1.Update(db);
    }
行中有一个SqlException

select * from Available where from = 'ahmedabad';
除了where子句之外,SQL查询工作得非常好。

From是SQL中的一个关键字。如果您有一个名称不好的列,您可以使用:

sqldataadapter.fill(datatable)
您还应该@fromopt:


请始终包含您收到的错误/异常消息,而不是存在某些sqlexception。从你的代码中,我不会总是像在这种情况下那么明显地看出哪里出了问题。好吧!下次我会注意的。不管怎样,谢谢你谢谢Hanks@Kobi。它现在正在工作,很抱歉在提问时出错了。下次我会小心的。
select * from Available where [From] = @fromopt
ncd.Parameters.AddWithValue("@fromopt", fromopt);