|
Are you getting a run-time error or are you just not seeing anything displayed when you are trying to populate your combobox? I haven't analyzed your code thoroughly yet, but try putting a breakpoint in the for loop that populates "Makes" from the db table to see if you're actually getting data out of it. If you ARE getting the correct data out of the table, follow the debugger down until you lose it. Reply back with what you find. (I don't have .NET available right now so I can't plug your code into a project to debug it yourself. ....So help me help you......help me......help you lol)
|
|
|
|
|
Thanks for your reply!
There is no run-time error. The code compiles and runs just fine. The form comes up but the combo box has nothing in it.
I've stepped through the code to make sure that the database connection sees the Access file.
|
|
|
|
|
...I think your problem is that you are executing a query rather and not storing it in an OleDbReader object. (this is all off the top of my head, mind you) If you are in VS, use Intellisense to see what db.ExecuteReader() returns...I think it's an OleDbReader object. You need to store the results in one and read from it instead of your db connection. I don't believe that "db" as you have defined it will work the way you are wanting to to work. You need a companion class to hold the results of a query and read from it. I can help you out with that, but I don't have the files handy. I'll get them real quick and I'll be back.
|
|
|
|
|
Yup...I was right. You need to store your "db.ExecuteReader" results in an OleDbReader object. I referred to a project that I'm currently working on and I think I might be able to help you out a little bit. I've only included the relevant portions of my code, but I accomplished exactly what you are trying to do. I wanted to populate a combobox with the contents of my "category" table. I'm not finished copying (Having to write it down by hand and bring it over...my development computer is not "plugged in" to my network) I'm going to go back, get more code and place it here in an edit. I'll let you know at the end of this post what I'm going to be bringing back next post
...a little bit of explanation. I have 2 classes (clsDatabase & clsQueryResults) that provide a layer of abstraction away from ADO.NET. This allows me to separate my application logic from database management commands.
The form code:
private void form_Load(object sender, System.EventArgs e)
{
ArrayList mCategoriesToDisplay = Manager.getAllCategories();
foreach(clsManager.clsCategory cat in mCategoriesToDisplay)
{
this.cbCategory.Items.Add(cat.Title);
}
}
"clsManager" code ...I use "clsManager" as a mediator to perform network and assembly linkage. If I were developing a desktop app, this would not be needed...just thought it might be helpful to explain why this layer of abstraction is even present
clsCategoryList mCategoryList;
.
.
.
public ArrayList getAllCategories()
{
return mCategoryList.getAllCategories();
}
"clsCategoryList" is basically my own way of holding my category objects. getAllCategories returns an ArrayList of clsCategory objects
public ArrayList getAllCategories()
{
string sql = "Select * From Category";
clsQueryResults resultSet = new clsQueryResults();
resultSet.Open(mDatabase, sql);
while(!resultSet.EOF)
{
clsCategory category = new clsCategory();
category.RestoreStateFromQuery(resultSet);
Categories.Add(category);
resultSet.NextRecord();
}
return Categories
}
The code I will bring you in my next post will be what happens when we move closer to ADO.NET as well as what happens inside the actual "clsCategory" object. ...clsCategory is the only place along the "data chain" that can actually interface with a clsDatabase object and a clsDatabase object is the only thing that can actually communicate with Access.
inside "clsQueryResults"
public void Open(clsDatabase database, string sqlQuery)
{
mProvider = database.getProvider;
if(mProvider.Equals("OLEDB"))
{
if(database.State == System.Data.ConnectionState.Open)
{
mOleReader = database.ExecuteQuery(sqlQuery)
}
}
else if(mProvider.Equals("SQLSRVR"))
{
}
NextRecord();
}
public void NextRecord()
{
if(mProvider.Equals("OLEDB"))
{
mEOF = !mOleReader.Read();
}
}
public bool EOF
{
get
{
return mEOF;
}
}
"clsDatabase" stuff
private OleDbConnection mDatabase = null;
.
.
.
public clsDatabase(string connectionString, string provider)
{
databaseProvider = provider.ToUpper();
connection = connectionString.ToUpper();
if(databaseProvider.Equals("OLEDB"))
{
mDatabase = new OleDbConnection();
mDatabase.ConnectionString = connectionString;
}
}
public OleDbDataReader ExecuteQuery(string sqlQuery)
{
OleDbCommand OleCmd = null;
if(mDatabase.State == System.Data.ConnectionState.Open)
{
OleCmd = new OleDbCommand();
OleCmd.Connection = mDatabase;
OleCmd.CommandText = sqlQuery;
}
return OleCmd.ExecuteReader();
}
"clsCategory"
.
.
.
public void RestoreStateFromQuery(clsResultSet resultSet)
{
this.Title = resultSet.GetColumnValue("CategoryTitle");
}
I did not include clsResultSet's "GetColumnValue" method...I left a little bit for you to do for yourself. Look up OleDbDataReader on the MSDN to find out how you should define this method. You're going to be looking specifically for "GetOrdinal" and "GetValue". I hope this helped out a little bit....actually I hope it helped a lot.
-- modified at 17:18 Friday 22nd September, 2006
|
|
|
|
|
Wow... thanks, mate! You're a huge help... I really appreciate this!
I just figured out that making the following change in my AppDatabaseInterface.cs file did the trick for me:
<br />
if (!found)<br />
alMakes.Add(make);<br />
but your approach on the whole seems better and I'm going to look into it.
Thank you very much!
N.
|
|
|
|
|
You're not using an object oriented design are you? I assume from your variable names that you're doing something with sound equipment?? Typically, you would do something like the following
public class clsSpeaker
{
private string mMake;
private string mModel;
public Speaker()
{
mMake = "";
mModel = "";
}
public void RestoreStateFromQuery(clsResultSet rs)
{
this.mMake = rs.GetColumnValue("SpeakerMake");
this.mModel = rs.GetColumnValue("SpeakerModel");
}
public string Make
{
get
{
return mMake;
}
}
public string Model
{
get
{
return mModel;
}
}
}
...so now, you can just instantiate your clsSpeaker class inside your UI, Deserialize it from your database query, and then do the command that I included in my previous post labeled as "form code." It makes the code much more legible and bug tracing is a lot easier because your code is properly compartmentalized.
btw, put your code in "pre" tags instead of "code" tags...It's a lot easier to read. (Pre tags are what I used to post my code in this thread)
|
|
|
|
|
I want to make a service which can watch and log data send and recived when any internet connection activates. I will be thankful for any pointers and help.
|
|
|
|
|
|
how can we use list for string members
|
|
|
|
|
using System.Collections.Generic;
...
List<string> listOfStrings = new List<string>();
listOfStrings.Add("hello");
listOfStrings.Add("world");
|
|
|
|
|
List<string> strings = new List<string>();
strings.Add("Hello");
Something like this? Your question is not very precise.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hey, I'm making use of Iphlpapi.dll, particularily CreateIpForwardEntry(ref PMIB_IPFORWARDROW pRoute)
I'm a little unclear as to what format I need to be using for the MIB_IPFORWARDROW structure
This is my declaration (?) of the structure:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]<br />
public struct PMIB_IPFORWARDROW<br />
{<br />
public UInt32 dwForwardDest;<br />
public UInt32 dwForwardMask;<br />
public UInt32 dwForwardPolicy;<br />
public UInt32 dwForwardNextHop;<br />
public UInt32 dwForwardIfIndex;<br />
public UInt32 dwForwardType;<br />
public UInt32 dwForwardProto;<br />
public UInt32 dwForwardAge;<br />
public UInt32 dwForwardNextHopAS;<br />
public UInt32 dwForwardMetric1;<br />
public UInt32 dwForwardMetric2;<br />
public UInt32 dwForwardMetric3;<br />
public UInt32 dwForwardMetric4;<br />
public UInt32 dwForwardMetric5;<br />
}
The ones I'm most confused about are dwForwardDest, dwForwardMask and dwForwardNextHop.
If I had a destination network of 10.11.0.0, mask 255.255.0.0 and the 'next hop' would be say... 10.11.7.3. The corresponding 'route add' command that I normally run from the command line is:
route add 10.11.0.0 mask 255.255.0.0 10.11.7.3
I get the feeling that I need to convert each octet to hex, but what do I do from there?
Any help would be greatly appreciated...
|
|
|
|
|
Converting each octet to hex doesn't get you any closer to a number. Instead you should convert each octet into a number, shift them and add them together.
For an example, the IP number 10.11.7.3 would add up as:
(10 << 24) + (11 << 16) + (7 << 8) + 3
---
b { font-weight: normal; }
|
|
|
|
|
I apologize, but I don't really understand what you're instructing me to do, what does (10 << 24) + ... mean?
Does anyone maybe have a bit of example code I could use as a guideline? I've found minimal assistance online so far..
|
|
|
|
|
The << operator shifts the first operand to the left the number of bits specificed by the second operand. As you have four bytes which should be positioned after each other in the uint, you shift the values to place the bytes at the correct position before adding them.
In binary it looks like this:
10 = 00001010
11 = 00001011
7 = 00000111
3 = 00000011
10 << 24 = 00001010000000000000000000000000
11 << 16 = 00000000000010110000000000000000
7 << 8 = 00000000000000000000011100000000
3 = 00000000000000000000000000000011
Adding them together gives the value:
00001010000010110000011100000011
Example code:
uint o1 = 10;
uint o2 = 11;
uint o3 = 7;
uint o4 = 3;
uint code = (o1 << 24) + (o2 << 16) + (o3 << 8) + o4;
---
b { font-weight: normal; }
|
|
|
|
|
OOOhhhhh that makes sense! Thanks a ton.
Should I be using uint instead of uint32? Not 100% sure what the difference is, will look it up a little later...
|
|
|
|
|
uint is just a synonyme for System.UInt32.
---
b { font-weight: normal; }
|
|
|
|
|
b_girl wrote: Should I be using uint instead of uint32? Not 100% sure what the difference is, will look it up a little later...
It's the same, sort of. uint is a C# keyword for the System.UInt32 .NET type.
However, be careful using an unsigned int. It's not CLS compilant, which means that there may exist other .NET languages that might not support unsigned integers/longs.
As long as you use this struct only in your application/dll where the code is not readable from outside (marked as internal , the default one), then you're safe.
But if you plan to use this code within another .NET language which does not support unsigned data types, the you must use int instead of uint
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks... I'll keep that in mind
|
|
|
|
|
|
I did see that earlier but it doesn't show the format I need to put the IP addresses in so that they are accepted. For example dwForwardDest = 10.11.0.0 would obviously not be correct.
|
|
|
|
|
Hi,
Well the title says it all
Anyone know how?
Thanks in advance!
|
|
|
|
|
Are you talking about the actual number of bytes in the file name? Or the number of bytes in a file specified by a file name? For the number of bytes in a file name, figure out which encoding you're interested in (ASCII? Unicode? etc.), then use System.Text.Encoding.[encoding name here].GetBytes .
|
|
|
|
|
Why would anybody want to get the number of bytes of a file name? I think the threadstarter just did not ask precise enough
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: Why would anybody want to get the number of bytes of a file name?
I have no idea, but that's certainly not the strangest request I've seen in this forum.
|
|
|
|