开发者

SqlDataAdapter issues

There are several queries to be performed which return the DataTable object. In order to speed up the development I created a private method which should return the dataset by taking the query string as an argument.

the method is the following:

private DataTable getDataTable(string query)
    {
        DataTable dt = new DataTable();
        SqlDataAdapter DA = new SqlDataAdapter(query, conn);
        try
 开发者_StackOverflow       {
            iStatusIndicator.SetBusy(true);
            iStatusIndicator.SetStatus("executing query" + query);
            DA.Fill(dt);
        }
        catch (Exception ex)
        {
            ...
        }
        iStatusIndicator.SetBusy(false);
        iStatusIndicator.SetStatus("");
        return dt;
    }

the procedure doesn't throw an exception but the DataTable dt is always null. I tried to run a query string directly in sql command prompt and it returns the data as expected so I don't know what could be the problem.

I would be very thankful if anyone of you explained the cause, suggested a fix or a better method for returning DataTables by receiving query strings.

Thank you


private static DataSet SelectRows(DataSet dataset,
    string connectionString,string queryString) 
{
    using (SqlConnection connection = 
        new SqlConnection(connectionString))
    {
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(
            queryString, connection);
        adapter.Fill(dataset);
        return dataset;
    }
}


What's in your catch block? By any chance is there something that does a return or exit sub? That seems to be the only way that I can see that this function would return NOthing (Ie. Your function is not ever reaching the "return dt;" line

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜