I created a DataSet Dynamicly which contains one table : Here is my DataSet
I want to fill it with values from my view Demande in my Database. I tried this code Here :
string cnstr = "Data Source=(local);Initial Catalog=Gestion Commercial Officielle;Integrated Security=True";
SqlConnection cn = new SqlConnection(cnstr);
cn.Open();
SqlDataAdapter daAuthors = new SqlDataAdapter("select * from Demande", cn);
DataSet1 d = new DataSet1();
daAuthors.FillSchema(d, SchemaType.Source, "Demande");
daAuthors.Fill(d, "Demande");
grid.DataSource = d;
grid.DataMember = "DataTable1";
It just returns an empty DataGridView like this .
Please could someone help please to figure out where i missed up ? Thank you in advance !
I finally found the solution , so here it is :
1- create dataSet in designer called report.xsd
2- create inside the dataset designer a table name it for exemple : demande
3-create a class where u fill your dataset . Here is the code :
class report
{
public void reportDemande (int n)
{
DataClasses1DataContext db = new DataClasses1DataContext();
reports.DemandeDataTable d = new reports.DemandeDataTable();
foreach(var i in db.tbl_detail_demande.Where(c=>c.id_demande==n) )
{
DataRow r = d.NewRow();
r[0] = i.code_article.ToString();
r[1] = i.tbl_article.designiation;
r[2] = i.quantite_demande;
r[3] = i.tbl_demande_achat.observation;
d.Rows.Add(r);
}
}
}
Hope it will help someone else in the futur .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.