how to fill in a data table from the database using data adapter,can show me the code? thk
Main Topics
Browse All Topicscan u provide me the sample/source code for fill the list view with data from sql server CE?
please help and please asap.thk u
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
A short example is available under:
http://msdn.microsoft.com/
You just need to provide the connection to the database and the SQL select command. Here is an example how a connection is created:
http://msdn.microsoft.com/
do u mean like this?this are my code...
private void comboBox1_SelectedIndexCha
{
if (comboBox1.SelectedIndex==
{
try
{
SqlCeConnection connection = new SqlCeConnection(_localConn
connection.Open();
//SqlCeCommand command = new SqlCeCommand("SELECT matric_no, student_Name, tutorial_grp FROM tutorial1Class_listCE WHERE tutorial_grp ='T01';", connection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("SELECT matric_no, student_name, tutorial_grp FROM tutorial1Class_listCE Where tutorial_grp= 't01';", connection);
adapter.Fill(dataset);
return dataset;
foreach (DataRow row in dataTable)
this.listView1.Items.Add (new ListItem (new string[] {row[0].ToString(), row[1].ToString(), ....}));
//SqlCeCommand command = new SqlCeCommand("SELECT matric_no, student_name, tutorial_grp FROM tutorial1Class_listCE Where tutorial_grp= 't01';", connection);
//IDataReader reader = command.ExecuteReader(Comm
//System.Text.StringBuilde
//while (reader.Read())
//{
listView1.Clear();
//ListViewItem item = new ListViewItem(reader.Item("
//item.SubItems.Add(reader
//ListViewItem item = new ListViewItem("Steve Martin");
//item.SubItems.Add("hi");
// listView1.Items.Add(item);
}
reader.Close();
}
catch (SqlCeException ce)
{
ShowErrors(ce);
}
catch (Exception er)
{
MessageBox.Show(er.ToStrin
}
finally
{
MessageBox.Show("ok", "RDA Lab");
}
This should be simple. Can you check this out - http://www.codeguru.com/Cs
cheers
well i check it out and it seen a bit hard to understand so i try this code but i got error
for this line of code.( ListViewItem item = new ListViewItem(reader.GetInt
can u tell me what does this line do, i think my data type is not int32 but is nvarchar.
SqlCeCommand command = new SqlCeCommand("SELECT matric_no, student_name, tutorial_grp FROM tutorial1Class_listCE Where tutorial_grp= 't01';", connection);
IDataReader reader = command.ExecuteReader(Comm
System.Text.StringBuilder sb = new System.Text.StringBuilder(
while (reader.Read())
{
listView1.Clear();
ListViewItem item = new ListViewItem(reader.GetInt
item.SubItems.Add(reader.G
//ListViewItem item = new ListViewItem(reader.Item("
//item.SubItems.Add(reader
//listView1.Columns.Add("S
//listView1.Columns.Add("M
//ListViewItem item = new ListViewItem("Diana");
//item.SubItems.Add("hi");
listView1.Items.Add(item);
}
reader.Close();
for this line of code.( ListViewItem item = new ListViewItem(reader.GetInt
can u tell me what does this line do, i think my data type is not int32 but is nvarchar.
This means that the first column is of type interger and is being converted into a string
If it is not a number in your case and is just a string , then say
ListViewItem item = new ListViewItem(reader.GetStr
If any of your columns return a number, then use the syntax in line 1 and substitute an appropriate column number.
cheers
Business Accounts
Answer for Membership
by: TheAvengerPosted on 2005-08-23 at 23:28:45ID: 14740053
Just fill in a data table from the database (using a data adapter) and then use something like this to fill in the ListView:
foreach (DataRow row in dataTable)
this.listView1.Items.Add (new ListItem (new string[] {row[0].ToString(), row[1].ToString(), ....}));
You should only take care that there are no empty values in some row, otherwise the row[i] would fail.