开发者

how can i fill the gridview with dataset?

this is my code :

    string aaa;
    aaa = Request.Params["aaa"];
    string strSel;
    if (aaa != "" && aaa != null)
    {
       // Response.Write("<script>alert('" + aaa + "');</script>");
        strSel = "Select * from inout where FName like '%" + aaa + "%'";

    }
    else
    {
        strSel = "Select * from inout";
    }
    Response.Write(strSel);
    string strProvider = "Server=(local);DataBase=AIS20060712101417;UID=sa;PWD=";
    Data0 ds= new Data0();
    SqlConnection MyConn = new SqlConnection(strProvider);
    MyConn.Open();
    SqlDataAdapter MyAdapter = new SqlDataAdapter开发者_如何学Python(strSel, MyConn);
    MyAdapter.Fill(ds,"inout");  
    GridView1.DataSource = ds;
    GridView1.DataBind();  

then the gridview is empty.


Is AutoGenerateColumns set to true ?

Try adding ds.Tables[0] as DataSource.


It's easy dear......Try this one it works well for me

 using (DataSet ds = new DataSet())
    {
        DataTable dt = new DataTable();
        ds.Tables.Add(dt);
        string str = "User ID=username;Password=password;Data Source=Test";
        OracleConnection conn = new OracleConnection(str);
        conn.Open();
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandText = "select * from table_name";
        cmd.CommandType = CommandType.Text;
        OracleDataAdapter da = new OracleDataAdapter(cmd); 
        da.Fill(dt);
        GridView2.DataSource = dt;
        GridView2.DataBind();
    }

And it's Done.Happy Coding with C#


I had the same problem. My solution was to remove the "*" and manually include the column names.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜