|
Hi,
if the non-comment lines are all "key=value" statements, AND assuming all keys are different, you could store them all in a Dictionary<string,string> making retrieval easy.
Note: Dictionaries don't preserve order, so if you were to modify and store the settings again, the file might look different (and your comments would be gone). If you want to keep comments and order, you could define your own little "MySettingItem" class to keep comment, key and value, and just build a List<MySettingItem> while reading the file.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Not sure if I understand correctly, but is it something as simple as:
string key = string.Empty;
string val = string.Empty;
if (splitArray.Count > 1)
{
key=splitArray[0];
val=splitArray[1];
}
at this point, you've got both elements of your configuration item that you can then do whatever you want with. HTH.
Josh
Find a penny, pick it up, and all day long you'll have a back-ache...
|
|
|
|
|
I prefer to use XML and then use a System.Xml.XmlDocument to read and write it.
|
|
|
|
|
I want the data stored in database to be displayed from the first record in the database. These data were submited to the database via textbox and I want to load the first record from database and display in the textbox.
below are the codes that I have check Beginners guide to accessing SQL Server through C# but can't still do it. No error but dont know what to do. Please I need help on this
Thanks
Ademola.
private void COMPANY_INFO_Load(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("user id=sa;" +
"password=admin123;server=ADEMOLAPC;" +
"Trusted_Connection=yes;" +
"database=Kay_Nylon_Db; " +
"connection timeout=30");
myConnection.Open();
//try
//{
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("select * from Company_Info", myConnection);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
Console.WriteLine(myReader["Company_Id"].ToString());
Console.WriteLine(myReader["Company_Name"].ToString());
Console.WriteLine(myReader["Company_Address_Line1"].ToString());
Console.WriteLine(myReader["Company_Address_Line2"].ToString());
Console.WriteLine(myReader["Fax"].ToString());
Console.WriteLine(myReader["Email"].ToString());
}
|
|
|
|
|
Your connection string is wrong to start with. If you supplied a username and password you do not use TrustedConnection.
The rest of the code looks reasonable, so long as the SQL statement is correct and there's data in the Company_Info table, and the column names are correct.
|
|
|
|
|
Thanks Dave,
I have removed the trusted connection but can not still retrieve from the database. All I want is onformLoad it should get the record from database and display it in textbox.
Expecting your reply
Ademola.
|
|
|
|
|
Don't "expect" anything from a site where you're not paying for support.
OK. Do you have this code inside a Try/Catch block?? Remove the code from inside the Try block. There's too many people not putting anything in the catch block, silently eating any errors.
If there are no errors, then the table is empty and there's nothing to return to you.
|
|
|
|
|
When I am working with a datareader, I always try and make sure that I actually received a datareader back from the ExecuteReader() call (ie "if(myReader != null)". I also check the HasRows property on the datareader object to verify that I have results to loop through. The way this is coded now, the while loop will read each record from the datareader. If data from the first row is all that is needed, calling myReader.Read() by itself will just read the first row (instead of using the while loop).
Josh
Find a penny, pick it up, and all day long you'll have a back-ache...
|
|
|
|
|
Ademola,
can you post the latest code your using. It is difficult to diagnose the problem without the code you are currently trying to run.
In the meantime, try to initialise your connection string using the connection string builder to rule out any typos in connection string.
SqlConnectionStringBuilder conn_str = new SqlConnectionStringBuilder();
conn_str.UserID = "your user_id";
conn_str.Password = "your password";
conn_str.InitialCatalog = "database name";
conn_str.DataSource = "sql server instance name";
conn_str.ConnectTimeout = "connection timeout (as an int)";
SqlConnection conn = new SqlConnection(conn_str.ConnectionString);
Also, make sure you rule out any accidently brain explosions, ie make sure datatable actually has data in it, your connecting to the right database, etc
Dave
|
|
|
|
|
can i fetch null field from database while showing it in textbox on page load event..???
|
|
|
|
|
hi,
How can i locate the form at the buttom rigth off the screen.
I can't do it manually, because the users have defferent screen size or definitions.
Thans for the help...
|
|
|
|
|
Do you mean the form in YOUR application, or ANY application?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
In my application.
Is there a difference if it's my application or any application?
|
|
|
|
|
Hi,
you can find out what screen you are using (when on a multi-monitor setup), get its resolution, then position the form appropriately. You would need the Screen class (maybe GetWorkingArea() method), and set the Form's StartPosition and Location properties.
BTW: you may have to take the selectable behavior of the task bar into account.
PS: for other apps, you would need to send Window messages and/or call Win32 API functions.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Screen currentScreen = Screen.FromRectangle(this.RectangleToScreen(ClientRectangle));
this.Location = new Point(currentScreen.Bounds.Right - this.Width, currentScreen.Bounds.Height - this.Height);
I know nothing , I know nothing ...
|
|
|
|
|
|
Hello,
I want to use the errorprovider control with checkboxes I have on a form.
I know with a textbox:
you can use something like if (textbox.text = <=0)
errorprovider.seterror(textbox,"you must enter data");
but with a checkbox am unsure of how to use
thank you
|
|
|
|
|
Um, have you tried:
errorProvider1.SetError(checkBox1,"Goodbye");
Works for me?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
johnnysmith1 wrote: but with a checkbox am unsure of how to use
That is dependent on the application of each checkbox.
|
|
|
|
|
Thinking about it more, just what error are you going to show for a checkbox? "This checkbox must be checked?" or "This checkbox must not be checked?"
Smacks of "Do not press this button" buttons to me.
I suspect it would be better for your user if you disable the checkbox when it can't be changed, rather than tell him he did something wrong.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
thank you- you are probaly right- thanks for help
|
|
|
|
|
|
If the author of the tool you have downloaded doesn't make the source available, my guess is that they don't want you to have it.
You shouldn't really ask people who write code for a living to help you steal it.
If you are unable to copy the GUI and unable to put the code together by using reflector, I doubt very much if you have the ability to code such an application, even if someone told you how to do the GUI.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
mind ur language. my motive was to understand how things like reflector work. if u don't have the answer at least don't speak nonsense and discourage people. exe are meant to hide code. and reflector to experiment with the same. ur answer shows ur incapability to understand the problem n solve the same. stop doubting others capabilities when u urself don't know.
others pls ignore this reply n help if they can.
thanks
|
|
|
|
|
I won't ignore that reply, it was extremely rude and disgusting at best, and uneducated and reflected your level of knowledge at the least.
Mind your language, and do conduct yourself accordingly. You are the one asking for help from us after all. If you don't like an answer from someone, ignore it. Don't insult. And by the by, you'd be lucky to get an answer form Henry Minute again, he's extremely helpful around these boards, try to show him the utmost respect.
|
|
|
|