Hi,
I need some help in creating a dataset that I can bind to a datalist after it has added a set of strings to it: - DataSet ds = new DataSet();
-
DataTable dt = new DataTable("table");
-
ds.Tables.Add(dt);
-
dt.Columns.Add("id");
-
dt.Columns.Add("description");
-
dt.Columns.Add("price");
-
-
for (int i = 0; i < Data.Count; i++)
-
{
-
string id = sourceofdata[i].id //Here is the main problem ** needs to be a cell item
-
-
string description = sourceofdata[i].description
-
}
-
-
DataList1.Datasource = ds;
-
DataList1.DataBind();
3 2009 vekipeki 229
Recognized Expert New Member
Use the DataTable.NewRo w() method to get a new row instance for that table, then set the individual columns for that row, something like this: -
for (int i = 0; i < sourceOfData.Length; i++)
-
{
-
DataRow dRow = dt.NewRow();
-
dRow["id"] = sourceOfData[i].Id;
-
dRow["description"] = sourceOfData[i].Desc;
-
dRow["price"] = sourceOfData[i].Price;
-
dt.Rows.Add(dRow);
-
}
-
-
dataList.DataSource = dt; // bind to a table
-
If sourceofdata is another table that looks the same you can use: - foreach (DataRow dr in sourceofdata.Rows)
-
{
-
...
-
}
if it's another DataSet: - foreach (DataRow dr in sourceofdata.Tables[0].Rows)
-
{
-
...
-
}
Change 0 to the index you want or the name of the table as string.
Hi did anyone have any problem using this code?
for (int i = 0; i < sourceOfData.Le ngth; i++)
{
DataRow dRow = dt.NewRow();
dRow["id"] = sourceOfData[i].Id;
dRow["descriptio n"] = sourceOfData[i].Desc;
dRow["price"] = sourceOfData[i].Price;
dt.Rows.Add(dRo w);
}
Everytime I use this, the first dRow does not have any data, it's all null. But then the next time this executes "dt.Rows.Add(dR ow); ", the one being inserted is the last dRow which is in i-1. So when I have 5 dRows, the first one is empty then then I'm not getting the last dRow.
I followed pretty much the exact code just the naming is different. What am I doing wrong?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Oz |
last post by:
This is long. Bear with me, as I will really go through all the convoluted
stuff that shows there is a problem with streams (at least when used to
redirect stdout).
The basic idea is that my application (VB.NET) will start a process,
redirect its stdout and capture that process' output, displaying it in a
window.
I've written a component for this, and a test application for the component.
It allows me to specify a command to execute,...
|
by: Jim Heavey |
last post by:
Trying to figure out the technique which should be used
to add rows to a datagrid. I am thinking that I would
want an "Add" button on the footer, but I am not quite
sure how to do that. Is that the best method? Do you
have a sample of how to do this?
|
by: dSchwartz |
last post by:
I need help adding a column to a dataset, but its a little bit more
complicated then just that. Here's the situation: I have many xml
files in one directory, each which represent a newsletter. I want to
create a page that will display a title and date of each newsletter,
along with a link to it. here's a code snip:
=============================
DirectoryInfo dirInfo = new
DirectoryInfo(Server.MapPath("/newsletters/xml/"));
|
by: Trevor |
last post by:
Hey,
I am trying to do this tutorial on the microsoft site :
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dndotnet/html/usingadonet.asp
I can get everything to work up to the DataAdd part
(Section heading is Adding Rows to a DataSet)
I dont really know what to do after i have added all the
|
by: Rudy |
last post by:
Hi all,
I know this is easy, just can't seem to get it. I have a windows form, and
a text box, with a value already in it. I need to add that value to a table.
It's just one value, so the entire row doesn't get filled. I have a
connection and all that stuff.
Private Sub btnPlaceBet_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPlaceBet.Click
' Dim Myds As Footbet.DStable
'...
| |
by: matt |
last post by:
hello,
can anyone speak to some of the common or preferred methods for
building Excel .XLS files, programmatically thru the .NET framework?
i have an intranet app that needs to generate & email .xls files for
users. these are not reports, but rather more like forms. its a pretty
simple doc, two worksheets -- the first is basic info common to all
recepients. the second is a simple data table that, depending on the
recepient, contains...
|
by: igotyourdotnet |
last post by:
How can i loop through my dataset if if colum 1 is there more then once
group them together
example:
dataset looks like this
BMW
BMW
BMW
LEXUS
LEXUS
|
by: Lord Zoltar |
last post by:
I built a small app with VS C# Express 2008, and published it as a
click-once app. I tried installing it on my local machine, and when I
click on its icon from the Start menu, nothing happens. Everything
works fine when I run the code from VisualStudio. I get this problem
if I use Debug or Release build config.
I'm sure it must be something rather simple, but I just can't seem to
find it.
|
by: greyseal96 |
last post by:
Hi,
I am a pretty new programmer, so I apologize in andvance if this is a dumb question...
In a book that I'm reading to learn C#, it says that when using a foreach() loop, a read-only copy of the iteration variable is used and you cannot modify it. For example:
int pins = {9, 3, 7, 2}
int newPin = 10;
foreach(int pin in pins)
{
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |