How to make a own dataview in c#? Can someone please help me? I want to get id and users and everything else from database to be showed in the same place at the same time just as DataView. Please help me. Need help for this. I can't find anything that I can use on google. I have searched for Howto make a dataset in c# but I'm new to programming. So please help me. =)
DataSet in C#?
Collapse
X
-
-
When you query the database you get a response that consists of the data matching your requirements, right? I would imagine you could display that data however you like: Make a chart of the numeric data by month... Song list by artist...Comment
-
Your own data that you want to show
If you want to show your data in the = manner, then I'd like to go for making a class of your own and setting properties there so that you can manipulate it later according your own wish.
Suppose I make a Car class like this :
Later I can add new values into the new instances of Cars by overloading the parameters. And show the values in various Label.Text....l ike thisCode:public class Car { //adding fields private string _make; private string _model; private int _price; //adding properties public string Make { get { return _make; } set { _make = value; } } public string Model { get { return _model; } set { _model = value; } } public int Price { get { return _price; } set { _price = value; } } //construcor public Car() { _make = "Default"; _model = "Defualt"; _price = 0; } //overloading public Car(string MAKE, string MODEL, int PRICE) { _make = MAKE; _model = MODEL; _price = PRICE; }
For the simple data manipulation, I'd like to go for the XML also. I can make an XMl file of my favourite author's list, like this:Code:protected void Button1_Click(object sender, EventArgs e) { Car zen1 = new Car("2002", "Maruti alto1", 60000); Label1.Text = "Year : " + zen1.Make; Label2.Text = "Model : " + zen1.Model; Label3.Text = "Price : " + zen1.Price.ToString(); Label7.Text = "----------------"; Car zen2 = new Car("2008", "Zen", 70000); Label4.Text = "Year : " + zen2.Make; Label5.Text = "Model : " + zen2.Model; Label6.Text = "Price : " + zen2.Price.ToString(); }
Now you make a BuisObject class creating Dataset dynamically, like this:Code:<?xml version="1.0" standalone="yes"?> <dsPubs xmlns="http://www.tempuri.org/dsPubs.xsd"> <xs:schema id="dsPubs" targetNamespace="http://www.tempuri.org/dsPubs.xsd" xmlns:mstns="http://www.tempuri.org/dsPubs.xsd" xmlns="http://www.tempuri.org/dsPubs.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="dsPubs" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="authors"> <xs:complexType> <xs:sequence> <xs:element name="au_id" type="xs:string" /> <xs:element name="au_lname" type="xs:string" /> <xs:element name="au_fname" type="xs:string" /> <xs:element name="au_phone" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> <xs:unique name="Constraint1" msdata:PrimaryKey="true"> <xs:selector xpath=".//mstns:authors" /> <xs:field xpath="mstns:au_id" /> </xs:unique> </xs:element> </xs:schema> <authors> <au_id>172-32-1176</au_id> <au_lname>Tagore</au_lname> <au_fname>Rabindranath</au_fname> <au_phone>408 555-0123</au_phone> </authors> <authors> <au_id>213-46-8915</au_id> <au_lname>Cohelho</au_lname> <au_fname>Paulo</au_fname> <au_phone>415 555-0120</au_phone> </authors> <authors> <au_id>100-01-1001</au_id> <au_lname>Chekhov</au_lname> <au_fname>Anton</au_fname> <au_phone>688 123-1340</au_phone> </authors> <authors> <au_id>102-02-1002</au_id> <au_lname>Leo</au_lname> <au_fname>Tolstoy</au_fname> <au_phone>408 555-8569</au_phone> </authors> </dsPubs> //as you see you can make this list longer, you can include other items here....
The rest of the part to show the lists by data binding with this BuisnessCobject .cs is a cake walk. There are several handy Framework Controls that you can drag and make them data-bound.Code:using System; using System.Web; using System.Data; namespace PubsClasses { public class AuthorClass { private DataSet dsAuthors = new DataSet("ds1"); private String filePath = HttpContext.Current.Server.MapPath ("~/App_Data/Authors.xml"); public AuthorClass() { dsAuthors.ReadXml(filePath, XmlReadMode.ReadSchema); } public DataSet GetAuthors() { return dsAuthors; } public void InsertAuthor(String au_id, String au_lname, String au_fname, String au_phone) { DataRow workRow = dsAuthors.Tables[0].NewRow(); workRow.BeginEdit(); workRow[0] = au_id; workRow[1] = au_lname; workRow[2] = au_fname; workRow[3] = au_phone; workRow.EndEdit(); dsAuthors.Tables[0].Rows.Add(workRow); dsAuthors.WriteXml(filePath, XmlWriteMode.WriteSchema); } } }
Hope this will help you.Comment
Comment