473,395 Members | 2,713 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,395 software developers and data experts.

In a STATIC corner

Am trying to adapt a pice of sample code in a proof of concept project
and can not seem to fugure out how to load the required values from a
database vs the static values in the sample.

Here is the Sample Class...
public class ModeItem : INotifyPropertyChanged
{
#region Creation

public static ModeItem[] GetModeItems()
{
// In a real app this would probably call into a data
access layer to get records from a database.
return new ModeItem[]
{
new ModeItem(1, "Item 1", "0"),
new ModeItem(2, "Item 2", "1"),
new ModeItem(3, "Item 3", "0"),
new ModeItem(4, "Item 4", "1"),
new ModeItem(5, "Item 5", "0"),
new ModeItem(6, "Item 6", "1"),
new ModeItem(7, "Item 7", "0"),
new ModeItem(8, "Item 8", "1"),
new ModeItem(9, "Item 9", "0"),
new ModeItem(10, "Item 10", "1"),
};
}

private ModeItem(int iItemID, string sItemName, string
sItemIcon)
{
this.ItemID = iItemID;
this.ItemName = sItemName;
this.ItemIcon = sItemIcon;
}

#endregion // Creation

#region Properties

public int ItemID { get; private set; }

string itemName;
public string ItemName
{
get { return itemName; }
set
{
if (value == itemName)
return;

itemName = value;

this.OnPropertyChanged("ItemName");
}
}

public string ItemIcon { get; private set; }

#endregion // Properties

#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler =
this.PropertyChanged;
if (handler != null)
handler(this, new
PropertyChangedEventArgs(propertyName));
}

#endregion
}
}
And here is what I want to do,
public class CategoryItem : INotifyPropertyChanged
{
private int itemID;
private string itemDescription;
private int itemIcon;

#region Public Properties
public int ItemID
{
get { return this.itemID; }
set { this.itemID = value; }
}

public string ItemDescription
{
get { return this.itemDescription; }
set
{
if (value == this.itemDescription)
return;

this.itemDescription = value;

this.OnPropertyChanged("ItemDescription");
}
}

public int ItemIcon
{
get { return this.itemIcon; }
set { this.itemIcon = value; }
}
#endregion // Public Properties

#region Creation
/// <summary>
///
/// </summary>
/// <returns>Categories</returns>
public static CategoryItem[] GetCategoryItems(string
sqlConnectionString)
{
OleDbConnection sqlConnection = new
OleDbConnection(sqlConnectionString.ToString());
string sqlQueryString = String.Format(@"SELECT [recID],
[catName], [catIcon] " +
"FROM [categories] " +
"WHERE [catActive] = 'True'");

sqlConnection.Open();

OleDbCommand oleDbCommand = new
OleDbCommand(sqlQueryString.ToString(), sqlConnection);
OleDbDataReader oleDbDataReader =
oleDbCommand.ExecuteReader();

while (oleDbDataReader.Read())
{
new CategoryItem(
oleDbDataReader.GetInt32(0),
oleDbDataReader.GetString(1).ToString(),
oleDbDataReader.GetInt32(2));
}
if (sqlConnection != null) sqlConnection.Close();

return TheCategory;
}

private CategoryItem(int iItemID, string sItemDescription, int
iItemIcon)
{
this.ItemID = iItemID;
this.ItemDescription = sItemDescription;
this.ItemIcon = iItemIcon;
}
#endregion // Creation

#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler =
this.PropertyChanged;
if (handler != null)
handler(this, new
PropertyChangedEventArgs(propertyName));
}

#endregion
}
Any help you can provide would be greatly appreciated.
Aug 22 '08 #1
1 1217
On Aug 22, 8:56*am, bgad...@nettopix.com wrote:
Am trying to adapt a pice of sample code in a proof of concept project
and can not seem to fugure out how to load the required values from a
database vs the static values in the sample.
PropertyChangedEventArgs(propertyName));
* * * * }

* * * * #endregion
* * }

Any help you can provide would be greatly appreciated.
Not quite sure what the problem is, but the biggest problem I had when
I studied databases was the connection: e.g., "OleDbConnection
sqlConnection = new OleDbConnection(sqlConnectionString.ToString()); "

You have to be sure your environment has security permissions that
allows you to work with SQL Server. It took me about a week of back
and forth with various newsgroups (the one that deals with SQL
specifically was very good, in particular a Scandanavian chap whose
name escapes me but who always is very helpful). I can't even tell
you how or what I did to make it finally connect, but it involved
switching and tweaking settings from the Administrator account (I was
using XP) and the user account, until finally I made the connection.
It was a several days project (a few hours every day) before I got it
to work.

As a last resort, I suggest this: just build a database, and manually
input the information exactly as the 'static values in the sample',
and then work from the newly created database. It's a pain to do the
manual input, but it's a last resort.

Good luck.

RL
Aug 22 '08 #2

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

Similar topics

1
by: Tristan Miller | last post by:
Greetings. Here is the scenario: I have an element div.aside which is absolutely positioned in the bottom right corner of its containing box, div.frame. Said containing box is then resized...
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
8
by: johkar | last post by:
I have two problems I cannot work out in the following tab code with Netscape 6. Problems are marked with all cap comments. One is that the background image is not shown in NS 6 (two places in...
0
by: qwu2008 | last post by:
All, I wanted to create a browser helper object that has a clickable icon at the right corner of the browser (similar to the Google notebook icon at the right corner of the browser). When the user...
4
by: mnowosad | last post by:
As far I know, static variables are tied to AppDomain scopes. So, every time an executing code within an AppDomain references a class for the the first time since the AppDomain was created/loaded,...
1
by: igpig | last post by:
Sorry if this has been asked before. I've searched the group and the FAQ and didn't find the answer. How can I retrieve x, y coordinates of the browser top left corner in Internet Explorer? ...
0
by: =?Utf-8?B?UmljaA==?= | last post by:
In a datagridview, the first column header cell is columnHeader(0), which is immediately to the right of the Top Left Corner Select All cell. And the first RowHeader cell is RowHeaderCell(0) which...
4
by: Andre Majorel | last post by:
How do you align an <imgagainst the bottom-right corner of an enclosing block so that the text in the block flows around it ? <!-- Block begins here --> <p> En ce qui concerne la conjoncture...
11
by: Simon van Beek | last post by:
Dear reader, By opening an application I get always the main Access window with the closing cross in the above right corner. Is there a possibility to make this closing cross invisible? ...
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: 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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.