Dataset problem

Now,everyone,here is the deal:

I have a sqldataapdater1,sqlcommand1,sqlconnection1,dataview,datagrid1:

here is the detail:(i want to see sql result in the datagrid1)

sqldataadapter1.selectcommand=sqlcommand1;

this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "PART", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("id", "id"),
new System.Data.Common.DataColumnMapping("desciption", "description"),
new System.Data.Common.DataColumnMapping("product_code", "product_code"),
new System.Data.Common.DataColumnMapping("commodity_code", "commodity"),
new System.Data.Common.DataColumnMapping("pref_vendor_id", "pref_vendor_id"),
new System.Data.Common.DataColumnMapping("purchased", "pruchased"),
new System.Data.Common.DataColumnMapping("fabricated", "fabricated"),
new System.Data.Common.DataColumnMapping("inspection_reqd", "inspection_reqd"),
new System.Data.Common.DataColumnMapping("buyer_user_id", "buyer_user_id")})});

sqlcommand1.commandtext="SELECT id, description, product_code, commodity_code, pref_vendor_id, purchased,
fabricated, inspection_reqd, buyer_user_id
FROM part";

sqlcommand1.connection=sqlconnection1;

sqlconnection1.connectionstring = "workstation id=p8747;data source=pst879;initial catalog=pds;user id=sa;password="1125&";persist security info=true;packet size=4096"

datagrid1.datasource=dataview1;

but i want to create a new dataset,and dataview1.table=dataset11.part

and last use the sqldataadapter1.fill(dataset11.part),so that i can see the result.

how can i complete this which command should i use to generate the dataset11



Answer this question

Dataset problem

  • Rocky79

    I'm not sure where is the problem...but if you want to see sql result in the grid code should be like this:

    SqlConnection con = new SqlConnection("workstation id=p8747;data source=pst879;initial catalog=pds;user id=sa;password="1125&";persist security info=true");

    Sqlcommand cmd = new SqlCommand("SELECT id, description, product_code, commodity_code, pref_vendor_id, purchased, fabricated, inspection_reqd, buyer_user_id FROM part", con)

    SqlAdapter sa = new SqlAdapter(cmd);

    DataSet ds = new DataSet();

    con.open();

    sa.Fill(ds);

    con.Close();

    DataGrid1.DataSource = ds.Tables[0];

    Best Regards,

    Misa Simic, MCSD .NET


  • Rattlerr

    string condition ="id like '%"+textBox3.Text+"%'"+" and commodity_code like '%"+comboBox4.Text+"%'"+" and product_code like '%"+comboBox3.Text+"%'"+" and pref_vendor_id like '%"+textBox2.Text+"%'";
    SqlCommand cmd = new SqlCommand("select id,description,pref_vendor_id,product_code,commodity_code,planning_leadtime,qty_on_hand,qty_on_order from part",con);
    SqlDataAdapter sa = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    con.Open();
    sa.Fill(ds);
    con.Close();
    DataView dv = new DataView(ds.Tables[0]);
    dv.RowFilter = condition;
    dataGrid3.DataSource =dv;

    okay,this problem is solved.


  • Sachin Chugh

    MisaSimic wrote:

    I'm not sure where is the problem...but if you want to see sql result in the grid code should be like this:

    SqlConnection con = new SqlConnection("workstation id=p8747;data source=pst879;initial catalog=pds;user id=sa;password="1125&";persist security info=true");

    Sqlcommand cmd = new SqlCommand("SELECT id, description, product_code, commodity_code, pref_vendor_id, purchased, fabricated, inspection_reqd, buyer_user_id FROM part", con)

    SqlAdapter sa = new SqlAdapter(cmd);

    DataSet ds = new DataSet();

    con.open();

    sa.Fill(ds);

    con.Close();

    DataGrid1.DataSource = ds.Tables[0];

    Best Regards,

    Misa Simic, MCSD .NET

    string condition ="part_id like '%"+textBox3.Text+"%'"+" and commodity_code like '%"+comboBox4.Text+"%'"+" and product_code like '%"+comboBox3.Text+"%'"+" and vendor_id like '%"+textBox2.Text+"%'";
    SqlConnection con = new SqlConnection("workstation id=pst01107;user id=sa;password=\"Pst09&\";persist security info=true;data source=pstadsp02;initial catalog=pst;packet size=4096");
    SqlCommand cmd = new SqlCommand("select id,description,pref_vendor_id,product_code,commodity_code,planning_leadtime,qty_on_hand,qty_on_order from part",con);
    SqlDataAdapter sa = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    DataView dv = new DataView(ds.Tables[0],condition);(i want to use dataview function,and use the condition to filter data)
    con.Open();
    sa.Fill(ds);
    con.Close();
    dataGrid3.DataSource =ds.Tables[0];(here i want to set DataSource to dv,is that okay )

    how can i do it



  • Dataset problem