Showing posts with label bit. Show all posts
Showing posts with label bit. Show all posts

Thursday, March 29, 2012

newbie: how to compare bit field from sql table to oledbdatareader?

Hi, I made a bit field off my sql table to represent true/false.
I'm having trouble to use compare the value off that table using OleDbDataReader, please help correct my code:
string connectionString = "(connect goes here)";
string sql = "SELECT isActived FROM List WHERE ID=@dotnet.itags.org.ID";
SqlConnection conn = new SqlConnection(connectionString);
SqlDataReader reader = null;
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
cmd.Parameters.Add("@dotnet.itags.org.license", "(my id number goes here)");
reader = cmd.ExecuteReader();
(something wrong with this code:) bool temp = reader["isActived"];
(or this:) if (
reader["isActived"] == true)
reader.Close();
conn.Close();
TIA

After a call to ExecuteRead, the reader is positioned before the first row. You must call reader.Read() to position the reader on a row before you attempt to access any data.


If you only get one value back, you may try this:
bool temp = cmd.ExecuteScalar();


thanks DMW, Jimmy, looks like ExecuteScalar would help me save a couple lines of code :)

Thursday, March 22, 2012

Newbie-time: OOP and ASP code separation?

Couple of softball questions on OOP and ASP.NET:

1. I am a bit uncomfortable with tangling class code with UI elements (e.g. result.innertext = object.method). Is it more customary to store some of the heavy-lift object class code elsewhere and simply call the objects from the aspx.cs. So, the aspx.cs does minimal processing, instead mapping results to the appropriate form elements?

2. If yes to #2, do I simply add new classes to my project? Is there any disadvanatge to this?

My thanks!

Paul

Hi,

yes you can put your heavy lifting in separate classes and call these from your codefile. In ASP.NET 2.0 you can keep those classes in the App_Data subfolder. You can even intermix several different .NET enabled languages:Using VB.NET and C# in the same ASP.NET 2.0 project.

Also take a look at thePersonal Starter Kit which shows some examples of this as well.

Grz, Kris.


Thanks for the help. I am off and running.

p