|
Um. Might have side effects[^]
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
skeeterz71 wrote: The string with the name ashley would be created at that time
Ok, think about this. You just said that if the user types a string into the Console or into a TextBox that a variable with the same name would be created. That's absurd for the following reason: What if the user typed:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursus justo arcu, quis euismod sapien blandit malesuada. Nam nisl augue, ornare id ipsum a, tristique feugiat justo. Donec sed eros id metus aliquam egestas. Donec fermentum condimentum mollis. Donec at auctor velit, non elementum purus. Maecenas congue, turpis non rutrum feugiat, magna ligula iaculis libero, eget aliquam erat magna at erat. Proin at mauris scelerisque, ultrices ipsum ac, mollis magna.
?? You really think a variable with that name is going to be created??
Seriously, you REALLY need to pickup a beginners book on C#. You will only serve to frustrate yourself if you don't properly learn the fundamentals.
|
|
|
|
|
Check to make sure the user entered anything by checking if the string is whitespace or null.
Checking if it is null is the most important.
Console.WriteLine(name + " What is her name?");
String herName = Console.ReadLine();
if(!String.IsWhiteSpaceOrNull(herName))
{
if(herName == "ashley")
{
do this stuff..
}
}
|
|
|
|
|
Hi, use this
if (herName == "ashley") instead of
if (herName == ashley)
This will resolve your error.
|
|
|
|
|
Reason for my vote of one: Three hours after Dave had posted this solution, with much better detail as to why to do it, you post exactly the same thing? How exactly is that supposed to help the OP?
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
For someone who posts in Q&A so much, I'm shocked at your shock
|
|
|
|
|
Thank you! that worked. I really appreciate your help. I got a lot of suggestions here and yours is the only one that worked.
|
|
|
|
|
As other suggested, You have problem with the if condition. First you need to learn about the difference between variable and it's value. In the given if condition you have herName as variable of type string. Now you need to compare string with string only. That could be possible either by comparing string variable like,
string storedName = "ashley";
if(herName == storedName)
Or by directly comparing string with the variable like,
if(herName == "ashley")
Before go for the solution oriented learning just read one of the beginner book or online materials(MSDN) to understand concepts.
Thanks
-Amit Gajjar
|
|
|
|
|
Hi There !
in myTable I have 4 fields , MyId,FName,Lname,Year,Code
I want to Filter "Code" when the "Year" Field is equel to TextForm Like 2005 or --> Year=2005.
try
{
OleDbConnection ocn = new OleDbConnection(ConnectionString);
OleDbDataAdapter oda = new OleDbDataAdapter(@"SELECT MyId,FName,Lname,Year=<a href="/Members/P1">@p1</a>,Code,FROM myTable WHERE Code=<a href="/Members/P2">@p2</a>", ocn);
oda.SelectCommand.Parameters.Clear();
oda.SelectCommand.Parameters.AddWithValue("<a href="/Members/P1">@p1</a>",txtYear.Text);
oda.SelectCommand.Parameters.AddWithValue("<a href="/Members/P2">@p2</a>",txtCode.Text);
DataTable dt = new DataTable();
dt.Clear();
oda.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("This Code Used Before");
txtCode.Focus();
}
else
{
...
Thanks a Lot
modified 1-Sep-13 4:26am.
|
|
|
|
|
Very difficult to read with the corrupted formatting.
I think the following may be what you want
Select Count(*) from MyTable where Year = @P1 or Code = @P2
Use executescalar and box the return as an int and test that value
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks
Excuse me for bad to Read :
a simple instance is Here :
I want to Edit my Records , and Prevent the Duplicate Records e.g. :
----------------------------------
YearReg RegNo
1950 112
1950 102
1951 110
1950 114
-----------------------------------
For example in The All Records that Year is 1950 , RegNo shoulbe Unique and if Year=1951 , RegNo also unique and etc.
heres my code For EditButton Click :
...
string strQ = @"SELECT COUNT(RegNo) FROM tblRcvLet WHERE YearReg=@s1"
OleDbDataAdapter oda_Edited = new OleDbDataAdapter(strQ, ocn);
oda_Edited.SelectCommand.Parameters.Clear();
oda_Edited.SelectCommand.Parameters.AddWithValue(" @s1", txtYearReg.Text);
DataTable dt_Edited = new DataTable();
dt_Edited.Clear();
oda_Edited.Fill(dt_Edited);
if (dt_Edited.Rows.Count > 0)
{
MessageBox.Show("Already Exists!! ");
txtRegNo.Focus();
}
else
{
OleDbCommand ocmd_Edited02 = new OleDbCommand();
ocmd_Edited02.CommandText = @"UPDATE ....
But I can Not Edit(Update) Records ...
Thanks a Lot
|
|
|
|
|
You can use datatable select option
string sql ="string strCondition = string.Format("Year = '{0}'", 2005);
DataRow[] row = dt.Select(strCondition);
|
|
|
|
|
I learn or relearn something every day - my excuse, I use collections these days.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Yes, it's possible. See this[^].
|
|
|
|
|
Absolutely yes.
You can keep the dll anywhere you want including the GAC where it could be shared across many applications.
|
|
|
|
|
HI,
Is there any way to find out user names who are currently accessing ACCESS database using C# window application.
Please suggest a solution.
Thanks
Bajrang
|
|
|
|
|
Generally, no. Access is a file-based desktop database. It doesn't have all of the facilities of a real SQL server.
|
|
|
|
|
thanks Dave for the reply.
But at least we can know how many users are accessing the DB.
Any clue.
Bajrang
|
|
|
|
|
Is this Access database sitting in a network share on a server?
|
|
|
|
|
yes some where in network
Bajrang
|
|
|
|
|
Then you can use DirectoryServices to get at it. You can find an example here[^].
|
|
|
|
|
You would need to trap the start and end events of the application part of the database, there is no system based logging of users in the database (it is a SINGLE user database after all).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: You would need to trap the start and end events of the application part of the database,
Presumably you mean in the C# application (versus the MS Access GUI app.)
|
|
|
|
|
jschell wrote: Presumably you mean in the C# application
God only knows, the poor bugger is using Access but as this is a C# forum, I presume you are correct.
Never underestimate the power of human stupidity
RAH
|
|
|
|