Hi guys,
I am trying to create a web interface in C# using ASP.NET. The database being used is SQL Server. I have some problems loading the tables in the datalist controls. When I run the program the DataList controls are loaded not with tables but something like this: "System.Data.DataRowView" in the three list boxe controls. Because I have three tables and I want to load them in the three list box controls. And then I want to select values from those three tables and a Textbox to redirect the user to another page to display information from those tables. Could you please tell me how to avoid the "System.Data.DataRowView"
populating into these three tables. Here is the code I used:
protected void Page_Load(object sender, EventArgs e)
{
// create the connection string and command string
string connectionString = "Server=.\\SQLEXPRESS;Database=NorthWind;Integrate d Security=SSPI;";
string commandString = "Select * from Customers";
string commandString1 = "Select * from Orders";
string commandString2 = "Select * from Employees";
//pass the strings to the sql data adapter constructor
SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, connectionString);
SqlDataAdapter dataAdapter1 = new SqlDataAdapter(commandString1, connectionString);
SqlDataAdapter dataAdapter2 = new SqlDataAdapter(commandString2, connectionString);
// create a data set
DataSet dataSet = new DataSet();
// fill the dataset object
dataAdapter.Fill(dataSet, "Customers");
dataAdapter1.Fill(dataSet, "Orders");
dataAdapter2.Fill(dataSet, "Employees");
//get the table from the dataset
DataTable dataTable = dataSet.Tables["Customers"];
DataTable dataTable1 = dataSet.Tables["Orders"];
DataTable dataTable2 = dataSet.Tables["Employees"];
//Bind to the Grid
ListBox2.DataSource = dataTable;
ListBox2.DataBind();
ListBox3.DataSource = dataTable1;
ListBox3.DataBind();
ListBox4.DataSource = dataTable2;
ListBox4.DataBind();
}
}
Thanks for your help.
Koonda
7 1778
dataAdapter.Fill(dataSet, "Customers");
dataAdapter1.Fill(dataSet, "Orders");
dataAdapter2.Fill(dataSet, "Employees");
//get the table from the dataset
DataTable dataTable = dataSet.Tables["Customers"];
DataTable dataTable1 = dataSet.Tables["Orders"];
DataTable dataTable2 = dataSet.Tables["Employees"];
//Bind to the Grid
ListBox2.DataSource = dataTable;
ListBox2.DataBind();
ListBox3.DataSource = dataTable1;
ListBox3.DataBind();
ListBox4.DataSource = dataTable2;
ListBox4.DataBind();
this is happening because you are binding the whole table to the list box. you have to bind it to one column of a table, not the whole table. so do something like:
ListBox2.DataSource = dataTable.columns(0)
or whatever you can find that works.
Thanks bplacker for your help but it still gives me an error which is like this:
Error 1 'System.Data.DataTable' does not contain a definition for 'colums'
Please don't get annoyed because I m new to .NET and I really need help. Would you be able to help me again.
Thanks
Koonda
try setting the datasource to the dataset, instead of the datatable.
listBox.dataSource = dataSet.Tables["Customers"].columns[0];
you are also removing one step of saving your datasets as datatables, which may run a little faster.
actually.. before you try that... you might have been on the right track, but you have to specify which column is going to be displayed. - ListBox2.DisplayMember = "columnname", or
-
ListBox2.DisplayMember = DataSet.Tables["TableName"].Columns["ColumnName"]
or something like this.
i think you can also set a value member, so that you can access something like the PK of a table later on when storing this value.
Thanks a lot bplacker for your time and help. But I still have this problem. It gives me error on your code. It gives errors on the column and it doesn't accept DisplayMember.
Could you please add some code within my code so I clearly where is the problem.
I appreciate your help.
Koonda
I don't know the exact syntax because I do most of my work in VB. One other method of doing this, which I usually use, is to go through a for each loop to fill the combo box with values. for instance,
for each dr as DataRow in DataSet.Tables["table"].Rows()
ListBox.Items.Add[dr.item["ColumnName"].toString.Trim
end for
like I said, the syntax is probably not perfect, but this should get you pretty close.
Thanks a lot bplacker,
I got it working a little bit. I am now getting the values from tables. It is possible to get the whole structure of table in the listbox in less coding or I have to specify all the columns. Anyways thants a lot for your help I really appreciate that. Now I want to select values of those tables from the listboxes of each tables and I have a textbox where I have to select the year from another table. Then I have submit button to display those slected values on another page. Do you have any Idea that How can I implement that.
Again thanks a lot for your help.
Koonda
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Simon X-Session |
last post by:
Hi !
I hope somebody can help me, i'm completly out of mind.
My problem:
I have a class inherited from Windows.Forms.Control named BasicModule,
which implements an interface named IModule...
|
by: Just D |
last post by:
All,
What are advantages and disadvantages of these two different approaches?
1 . I create a base class with a few virtual methods, then I derive my
classes from this class, override these...
|
by: .Net Sports |
last post by:
I am resurrecting an old script from a previous programmer, and want to
migrate it over to asp.net from classic asp. Tho there are other
peripheral parts of the script (that really have no bearing...
|
by: Ravi |
last post by:
Hi all.
Help needed Regarding vb.net.
I have the User Interface of my application, Which has a treeview on
the left and a set of panels on the right(which have textboxes).
When Ever i Click a...
|
by: MA |
last post by:
Hi,
I'm strugling with tho following case:
I use a datalist in my asp.net application to present an interface to the
use where he/she can modify some database tables. In de "update mode" I...
|
by: YellowFin Announcements |
last post by:
Introduction
Usability and relevance have been identified as the major factors
preventing mass adoption of
Business Intelligence applications. What we have today are traditional
BI tools that...
|
by: koonda |
last post by:
Hi guys,
I posted my messages before and one of the members helped me a lot. Now I have another problem with the web Interface. I can populate the listboxes with tables from database.The code...
|
by: saintlyav |
last post by:
I recently made a python module which calls functions from a c program. I used SWIG to generate the wrapper code from an interface file, and compiled the module into a dll which i can import in...
|
by: vamsioracle |
last post by:
hi all
I ran Import Price Catalogs open interface to load data from interface tables into base tables (PO_Headers_all, PO_LINES_ALL and PO_DISTRIBUTIONS_ALL).
the program ran succesfully. Now...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |