473,692 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataTable/DataSet

Hello, I have done a little VB Programming and now I am giving C# a try.
Right now I am working with Dataset and DataTables and there are a couple
of compile errors that I would work in VB, but are apparently different in
C#.

If I want a table from a DataSet, in VB.Net I would enter the command as
follows:

Dim Table as DataTable = ds.Tables("MyTa ble")

I tried this in C#

DataTable tbl = ds.Tables("Even ts");
To get an item from a dataReader into a DataROW Field I would use a command
which looks like the following:

Row.Items("MyFi eld") = dr.items("Field 1")

IN C# I tried...
row(0) = dr.GetInt16(0);

When I create a column in a DataTable in VB.Net, I would enterer

Tbl.Columns.Add ("MyField", getType(System. String))

In C# I tried

tbl2.Columns.Ad d("ClubID", GetType(System. Int16));

What am I doing wrong?
Nov 15 '05 #1
2 15314
Arrays in C# have square brackets, like this [ ] . I've stumbled myself over
these quite a few times... :-)

For example
DataTable tbl = ds.Tables["Events"];

The GetType method is in C# typeof(...):
tbl2.Columns.Ad d("ClubID", typeof(System.I nt16));

--
Greetz,
Jan
_______________ _______________ ____
Read my weblog: http://weblogs.asp.net/jan
"Jim Heavey" <Ji*******@nosp am.com> schreef in bericht
news:Xn******** *************** **********@207. 46.248.16...
Hello, I have done a little VB Programming and now I am giving C# a try.
Right now I am working with Dataset and DataTables and there are a couple
of compile errors that I would work in VB, but are apparently different in
C#.

If I want a table from a DataSet, in VB.Net I would enter the command as
follows:

Dim Table as DataTable = ds.Tables("MyTa ble")

I tried this in C#

DataTable tbl = ds.Tables("Even ts");
To get an item from a dataReader into a DataROW Field I would use a command which looks like the following:

Row.Items("MyFi eld") = dr.items("Field 1")

IN C# I tried...
row(0) = dr.GetInt16(0);

When I create a column in a DataTable in VB.Net, I would enterer

Tbl.Columns.Add ("MyField", getType(System. String))

In C# I tried

tbl2.Columns.Ad d("ClubID", GetType(System. Int16));

What am I doing wrong?

Nov 15 '05 #2
Jim,

The major problem I see is your syntax.

DataTable tbl = ds.Tables("Even ts");
DataTable tbl = ds.Tables["Events"]; //need to use square brackets

Row.Items("MyFi eld") = dr.items("Field 1");
Row.Items["MyField"] = dr.items["Field1"];//need to use square brackets

this one is a little more work:
Tbl.Columns.Add ("MyField", getType(System. String))

DataColumn column = new DataColumn("myF ield");
column.DataType = Type.GetType("S ystem.Int32");//Nedd to enclose the type in
"Quotes"
Tbl.Columns.Add (column);

If you are already comfortable with VB syntax, perhaps you should consider
coding in VB.NET. You might find the learning curve a little easier.

Hope this helps

Marco

"Jim Heavey" <Ji*******@nosp am.com> wrote in message
news:Xn******** *************** **********@207. 46.248.16...
Hello, I have done a little VB Programming and now I am giving C# a try.
Right now I am working with Dataset and DataTables and there are a couple
of compile errors that I would work in VB, but are apparently different in
C#.

If I want a table from a DataSet, in VB.Net I would enter the command as
follows:

Dim Table as DataTable = ds.Tables("MyTa ble")

I tried this in C#

DataTable tbl = ds.Tables("Even ts");
To get an item from a dataReader into a DataROW Field I would use a command which looks like the following:

Row.Items("MyFi eld") = dr.items("Field 1")

IN C# I tried...
row(0) = dr.GetInt16(0);

When I create a column in a DataTable in VB.Net, I would enterer

Tbl.Columns.Add ("MyField", getType(System. String))

In C# I tried

tbl2.Columns.Ad d("ClubID", GetType(System. Int16));

What am I doing wrong?

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2618
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes, then written to the database... or at least that's what's supposed to be happening. Unfortunately, I've discovered that while it appears that when I create a new record/row I'm successfully updating the Access database, once the Update is...
1
6819
by: Somebody_Out_There | last post by:
Hello, I am trying to create a strongly typed datatable/dataset from an untyped dataset or datatable returned from a stored proc. The structure of the table cannot be static since the results are dynamic which means that I am right now creating the schema/structure of the datatable from a datareader using reader.GetSchemaTable() and then looping thru the reader to populate values. Is there any other efficient way of achieving this?...
3
2518
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and others. One of the custom format is as follows: dsmessages_dt.Columns.Add("Image", GetType(Image)) I had a problem of when I used a checkbox in the grid that was bound to the datatable that it would not update my dataset. So I created another...
1
3733
by: George | last post by:
Hi, I have a DataGridView, bounded to a DataTable which is populated/updated by a OleDbDataAdapter (with OleDbConnection) to an Access Database. (Sounds familiar to some of you ... I have posted a number of related questions already.) I want to have a worker thread starting to consume data from the DataTable. Imagine that the DataTable contains a list of tasks. From the C# .NET specification, DataTable "is safe for multithreaded...
1
1309
by: Tom W | last post by:
code snipped from MS sample "N-Tier Data Form and Data Layer" example (101 vb.net samples). Public Class frmMain Private dsSupplierProducts as DataSet Private dtSupplier as DataTable Private dtProducts as DataTable Private dvSupplier as DataView Private dvProduct as DataView
2
2529
by: Aryan | last post by:
Hi, I am implementing Business object, but while implementing this I want to have DataTable or DataSet as part of Business Object. For example, I want to bind controls directly to these Business Objects. So please suggest me how can I achieve this?? Is is good to create a Property in Business Object which will have return type as "DataTable / DataSet"?? or what could be the optimum way to achieve the same.
0
895
by: riyap | last post by:
Hi i have a question regarding a update in msaccess DB using string builder,DATA SET AND DATA RELATIONS can we do that in access DB i have a table in access i need to pass more than 1 record and get o/p value and update in table again so for this i used : i have 2 datatables which i loaded with select command n records in dlog1 ,dlog2 so im passing log 1 values into oracle stored procedure ,i got the values and im loading it in log3...
5
1260
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have a Datatable/Dataset that I'd like to update back to the server. How do I go about saving changes to my Datatable or Dataset back to the database?
5
8635
by: Frank Hauptlorenz | last post by:
Hello, I recognized some days ago, that returning a DataTable blocks my WCF-Service. Is this a known bug? If I add this table to a new DataSet() and return this, it works. Thank you, Frank
0
8604
marktang
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...
0
8538
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,...
0
8961
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6459
isladogs
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...
0
5819
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2974
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
2
2238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1957
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.