Monday, March 12, 2012

Why VB works but C# doesnt for these?

After fill a DataSet, I want to get two records to put into TextBox. In VB, the code lines are

Dim DSTime AS New DataSet()
myCommandTime.Fill(DSTime,"Time")

txtSemester.Text = DSTime.Tables("Time").Rows(0)("Content_Admin").toString()
txtDeadLine.Text = DSTime.Tables("Time").Rows(1)("Content_Admin").toString()

However, when I tried to convert into C#, I can't make it work.

DataSet DSTime = new DataSet();
myCommandTime.Fill(DSTime,"Time");

txtSemester.Text = DSTime.Tables["Time"].Rows[0]("Content_Admin").toString();
txtDeadLine.Text = DSTime.Tables["Time"].Rows[1]("Content_Admin").toString();

Does C# has itself syntex for that?

Thanks.Hello try to use this:

txtSemester.Text = DSTime.Tables[0].Rows[0][1].toString();
txtDeadLine.Text = DSTime.Tables[0].Rows[1][1].toString();

Considering that Content_admin is column #1.

Good Luck.
Thanks you very much.

But, the second element should be 0 instead of 1. Here it works

txtSemester.Text = DSTime.Tables[0].Rows[0][0].ToString();
txtDeadLine.Text = DSTime.Tables[0].Rows[1][0].ToString();
Glad to help you my friend,

Good Luck.

0 comments:

Post a Comment