0

dataSet を返すメソッドを実行しようとしていますが、接続文字列が機能しません。

私はこれを試しました:

    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 に答える