0

我正在尝试做一个返回数据集的方法,但连接字符串不起作用。

我试过这个:

    public DataSet list()
    {
        // First Create a New Connection
        System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection();
        // Now Pass a Connection String To the Connection


        sqlConnection1.ConnectionString = "Data Source=mysite.com.br;User ID=admin_devr;Password=123456;Initial Catalog="rave_dbteste" providerName="System.Data.OleDb";
        // Now the Select statement you want to run
        string select = "select * from table";
        // Create an Adapter
        SqlDataAdapter da = new SqlDataAdapter(select, sqlConnection1);
        // Create a New DataSet
        DataSet ds = new DataSet();
        // Fill The DataSet With the Contents of the Stock Table
        da.Fill(ds, "cdestacionamento");
        // Now Return ds which is a DataSet
        return (ds);
    }

怎么了?

4

1 回答 1

0

我认为您在连接字符串行写入以下内容后没有打开连接

sqlConnection1.Open();

并总是这样检查

 if (sqlConnection1.State == ConnectionState.Closed)
                    sqlConnection1.Open();
于 2012-10-12T04:33:29.180 回答