473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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("MyTable")

I tried this in C#

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

Row.Items("MyField") = dr.items("Field1")

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.Add("ClubID", GetType(System.Int16));

What am I doing wrong?
Nov 15 '05 #1
2 15303
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.Add("ClubID", typeof(System.Int16));

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Jim Heavey" <Ji*******@nospam.com> schreef in bericht
news:Xn*********************************@207.46.24 8.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("MyTable")

I tried this in C#

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

Row.Items("MyField") = dr.items("Field1")

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.Add("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("Events");
DataTable tbl = ds.Tables["Events"]; //need to use square brackets

Row.Items("MyField") = dr.items("Field1");
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("myField");
column.DataType = Type.GetType("System.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*******@nospam.com> wrote in message
news:Xn*********************************@207.46.24 8.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("MyTable")

I tried this in C#

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

Row.Items("MyField") = dr.items("Field1")

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.Add("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
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,...
1
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...
3
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...
1
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...
1
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...
2
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...
0
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...
5
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
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,...
0
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...

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.