DataSets - Class Model - How to get Bool value from DataSet

I am new to C # and ASP.net. I am a ColdFusion programmer, but I am on ASP.net.

I will give details, then ask my question ....

I managed to get it when I call the code “Service Layer Class Code” (or “Logical Business Layer”) from the code and then that it calls the file of the data access level class. I send back the DataSet from the data access layer, and then to the code behind moving the code to the table so that I can read it line by line.

I was looking for a way to get the Boolean values ​​when I was on the Edit screen, to check the boxes to check when I found this post.

C # Assigning DataRow ["haswhatnots"] = hasWhatnots is awfully slow

I see a mention that they should ...

Alternatively, use a class model instead of a DataTable, which sounds great if that's what I think.

What is the best way to make CRUD screens in which you use a Class file to pull data and what format should the data contain?

I use ColdFusion data returned in a QuerySet, and then we can skip it. We can convert his query to Array of Structures or Array Obects, XML or JSon, but I still run into problems understanding HOW to retrieve data from a DataSet when I return it. I am getting String Data right now, but maybe there is a very simple one page example ...

I want to find out how to get Boolean values ​​right now, this is my current problem.

Thanks for any help, Nathan.

P.S. , . (Presentation/CodeBehind/Service/Data Access).

Protected void Page_Load(Object sender, EventArgs e)
{
if(!IsPostBack)
{

DataTable dt = new DataTable();
DataRow dr;

PageService myPage = new PageService();
DataSet ds = myPage.getPages();

int rowCount = ds.Tables[0].Rows.Count;
ds.Columns.Add(new DataColumn("PageID", typeof(Int32)));
ds.Columns.Add(new DataColumn("Name", typeof(String)));
ds.Columns.Add(new DataColumn("PageHTMLContent", typeof(String)));
ds.Columns.Add(new DataColumn("NavigationText", typeof(String)));
ds.Columns.Add(new DataColumn("TopMenu", typeof(Boolean)));
ds.Columns.Add(new DataColumn("SubMenu", typeof(Boolean)));
ds.Columns.Add(new DataColumn("DisplayOrder", typeof(Int32)));
ds.Columns.Add(new DataColumn("Active", typeof(Boolean)));

for (int i = 0; i < rowCount; i++)
{
  dr = dt.NewRow();
  dr[0] = i;
  dr[1] = i.ToString;
  dr[2] = i.ToString;
  dr[3] = i.ToString;
  dr[4] = i;            // Not sure what to do here for the Boolean Value
  dr[5] = i;  // Not sure what to do here for the Boolean Value
  dr[6] = i;
  dr[7] = i;  // Not sure what to do here for the Boolean Value
}

ds.Tables.Add(dt);
foreach (DataRow dataRow in ds.Tables[0].Rows)
{
  PageIDHiddenField.Value = dataRow["PageID"];
  NameTextBox.Text = dataRow["Name"].ToString();
  PageHTMLContentTextBox.Text = dataRow["PageHTMLContent"];
  NavigationTextTextBox.Text = dataRow["NavigationText"];
  TopMenuCheckBox.Checked = dataRow["TopMenu"];           // Not sure what to do here for the Boolean Value
  SubMenuCheckBox.Checked = dataRow["SubMenu"];           // Not sure what to do here for the Boolean Value
  DisplayOrder.Text = dataRow["DisplayOrder"].ToString();
  ActiveCheckBox.Checked = dataRow["Active"];             // Not sure what to do here for the Boolean Value
}
}
}
+3
1

. dataRow indexer object, . Boolean :

TopMenuCheckBox.Checked = (bool)dataRow["TopMenu"];

DataSet, - :

DataSet ds = myPage.getPages();

foreach (DataRow row in ds.Tables[0].Rows)
{
    PageIDHiddenField.Value = row["PageID"];
    NameTextBox.Text = (string)row["Name"];
    ...
    TopMenuCheckBox.Checked = (bool)row["TopMenu"];
}

index dataRow indexer, .

+4

Source: https://habr.com/ru/post/1755972/


All Articles