Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Windows forms with database
 

Windows forms with database

How to populate data from database to windows forms and save as xml file with TABLE's AUTONUMBER as the file name.
Vaish  Tuesday, September 12, 2006 4:21 PM

here is a small example.

SqlCommand theSQLCommand = new SqlCommand("SELECT * FROM tableName");

theSqlCommand.Connection = new SqlConnection(connectionString);

DataSet theDataSet = new DataSet();

SqlDataAdapter theSqlDataAdapter = new SqlDataAdapter(theSqlCommand);

theSqlCommand.Connection.Open();

theSqlDataAdapter.Fill(theDataSet);

theSqlCommand.Connection.Close();

theDataSet.WriteXml(filename);

you would need to import/use the System.Data.Net; namespace

does this help? This is just a small example on retrieving all records from a table and filling the dataset with the results, finally saving it to a file giving it the filename. You can get the tableName automatically generated by looking at the Table property in the DataSet:

theDataSet.Tables[index].TableName;

ahmedilyas  Tuesday, September 12, 2006 6:06 PM

you can fill a dataset with data from the database using a DataAdapter for your connection (SQL or OleDb) and then save the data using the dataset WriteXml() method. There are many examples on these forums on filling a dataset from a database query

 

it would also help if you specified what language you are using to develop with as well as the framework version

ahmedilyas  Tuesday, September 12, 2006 4:34 PM
Hi

Thank you very much for yr swift reply. I am using C-sharp (Dot Net) also new for this language. I try to save the data as XML file but the file name should be autonumber of the table from that database also I look around the forum.

Many thanks
vaish
Vaish  Tuesday, September 12, 2006 6:02 PM

here is a small example.

SqlCommand theSQLCommand = new SqlCommand("SELECT * FROM tableName");

theSqlCommand.Connection = new SqlConnection(connectionString);

DataSet theDataSet = new DataSet();

SqlDataAdapter theSqlDataAdapter = new SqlDataAdapter(theSqlCommand);

theSqlCommand.Connection.Open();

theSqlDataAdapter.Fill(theDataSet);

theSqlCommand.Connection.Close();

theDataSet.WriteXml(filename);

you would need to import/use the System.Data.Net; namespace

does this help? This is just a small example on retrieving all records from a table and filling the dataset with the results, finally saving it to a file giving it the filename. You can get the tableName automatically generated by looking at the Table property in the DataSet:

theDataSet.Tables[index].TableName;

ahmedilyas  Tuesday, September 12, 2006 6:06 PM
Hi

Thank you very much.

I have started this project but in VB(visual studio 2005) but struck in the following

1.Created a combobox and it is displaying one field from the lookup table. But I want combobox to display two field (ex: ID, Description)in the DROPDWON LIST and display only ID when user selected.

Many thanks
Vaish  Thursday, September 21, 2006 2:34 PM
not sure I quite follow, you want to display 2 fields and display only 1 field (ID) when user selects it from the dropdown list?
ahmedilyas  Thursday, September 21, 2006 2:46 PM
Hi

I have a lookuptable with two field. (ID , Description)

When user clicks the combox's drop down menu, both field (ID, Description) should display in the drop down list (i.e The row of the table). Once the user selected from the drop down list only the ID will be shown in the control or Combobox.




Vaish  Thursday, September 21, 2006 3:12 PM

You can use google to search for other answers

Custom Search

More Threads

• Datasource and a serializable array...
• Problems with overwriting datagridview's paint methods
• Lower case 'q' keystroke doesn't work inside a Custom Cell of Data Grid View control
• Merge a particular column header in DataGridView C#
• ComboBox with List<CustomClass> Datasource problem.
• TreeGrid Control
• DataGridView Search
• Display data and modify the layout
• questions about flexibility when using BindingSource/TableAdapter/TableAdapterManager
• Need Help: StackOverflowException on DatagridView RowValidating event