|
Hey, i was refering to this section of my code:
while (mysqlReader.Read())
{
string strusername;
string strpassword;
strusername = (mysqlReader["username"].ToString());
strpassword = (mysqlReader["password"].ToString());
if (strusername == uname && pword == strpassword)
{
main_screen mss = new main_screen();
mss.Show();
}
else
{
textBox3.Text = "YOU ARE LOGGED IN!";
}
}
isn't the if statement proving that the username and password exists? (in response to; "youve programmed it to do nothing")
isn't the main screen form supposed to open if there is a match between username and password?
and the if else statement textBox3.Text is supposed to show "you are now logged in"?
Neither of these are happening which means that somewhere the code is not working.
Merry Christmas by the way and thanks again for your comments!
|
|
|
|
|
I'm sorry, I didn't look right.
I think there are no records that meet the criteria.
My books says to use a data reader for performance reasons, but I've found that a data reader can even take longer than a dataset, so I always use a data set (perhaps if I make a million records application the datareader comes into play again).
The advantage of the dataset is you can check it in debug mode.
I have a standard function:
public static DataTable dtAlgemeen(string sql, string NaamRetourTabel)
{
MySqlConnection ConnMySQL;
MySqlCommand cmdMySql = new MySqlCommand();
ConnMySQL = new MySqlConnection(ConnectString());
cmdMySql.Connection = ConnMySQL;
try
{
ConnMySQL.Open();
MySqlDataAdapter da = new MySqlDataAdapter();
da.SelectCommand = new MySqlCommand(sql, ConnMySQL);
MySqlCommandBuilder sqlbuilder = new MySqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, NaamRetourTabel );
DataTable dt = ds.Tables[NaamRetourTabel];
return dt;
}
catch (Exception e)
{
System.Windows.Forms.Clipboard.SetText(sql);
System.Windows.Forms.MessageBox.Show("Foutmelding:" + e.Message + Convert.ToChar(13) + e.GetType().ToString() + Convert.ToChar(13) + "SQL is niet uitgevoerd, SQL text gekopieerd naar clipboard");
return null;
}
finally
{
ConnMySQL.Close();
}
}
then I code in my main routine
DataTable dtUsers = dtAlgemeen("Select * from users", "users");
If you put a break on the next line you can see the actual data extracted from the database by clicking on the magnifying glass that appears when you hold the mouse pointer over the dtUsers word.
If the data is satisfactory, you can adjust your code to select only the record with the necessary data
string sql = "Select * from users where username = '" + this.TextBox1.Text + "' And password = '" + this.TextBox2.Text + "'";
dtUsers = dtAlgemeen(sql, "users");
if (dtUsers.Rows.Count ==0)
{
MessageBox.Show("Username does not exist, or Password invalid");
}
else
{
MessageBox.Show("You are now logged in");
//do your other things
}
Use the debugger to check your code line by line to see if the expected result occurs!
Rob
|
|
|
|
|
The documentation of ReaderWriterLockSlim.EnterUpgradeableReadLock says:
"A thread in upgradeable mode can downgrade to read mode or upgrade to write mode."
How do I downgrade the lock to a read lock? The documentation does't tell...
|
|
|
|
|
To upgrade to write mode call EnterWriteLock and to downgrade, call ExitWriteLock
|
|
|
|
|
Thanks, but I meant to downgrade from UpgradeableReadLock to simple ReadLock. I don't need WriteLock. The rationale is that since only one thread can acquire UpgradeableReadMode, I want to downgrade it when I know it's not needed so that another thread can acquire it.
|
|
|
|
|
Well, the below code will answer it
class Program
{
static ReaderWriterLockSlim rwSlim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
static void Main(string[] args) {
rwSlim.EnterUpgradeableReadLock();
Console.WriteLine(rwSlim.IsUpgradeableReadLockHeld);
rwSlim.EnterReadLock();
Console.WriteLine(rwSlim.IsReadLockHeld);
rwSlim.ExitUpgradeableReadLock();
Console.WriteLine(rwSlim.IsUpgradeableReadLockHeld);
rwSlim.ExitReadLock();
Console.WriteLine(rwSlim.IsReadLockHeld);
}
} You need to supply LockRecursionPolicy.SupportsRecursion to indicate that you need recursive locks.
|
|
|
|
|
Hi,
Am working in Asp.net using C#.I have 4 textboxes and 1 button in my application.After the user enters values in 4 textboxes he will click the button.On button click the values in textbox should be written in XML format....Usually to insert values in database we will use INSERT query..But instead of saving in Database i should write the values in textbox directly to XML.
S it possible to write the values in Textbox directly to xml???
Can u help me in doing this....Thanx in advance..
Regards,
Samson
|
|
|
|
|
Yes, that is possible. Try this little horrorcode;
string asXML = @"<codinghorrorxml>" + Environment.NewLine;
asXML += @"<textbox1>" + textBox1.Text + @"</textbox1>" + Environment.NewLine;
asXML += @"<textbox2>" + textBox2.Text + @"</textbox2>" + Environment.NewLine;
asXML += @"<textbox3>" + textBox3.Text + @"</textbox3>" + Environment.NewLine;
asXML += @"</codinghorrorxml>";
You'll also need to write this string to disk, I presume. There's a StreamWriter somewhere in System.IO.
I are troll
|
|
|
|
|
hi,
I don know how to use streamwriter and save the xml...
Please give me some idea over there...
Thanks in advance
Regards,
Samson
|
|
|
|
|
There's an example here.
Good luck
I are troll
|
|
|
|
|
Hi,
I created the code and run it but it's not creating a new xml file... I pasted my code her... please let me know what to correct it
string asXML = @"" + Environment.NewLine;
asXML += @"" + txtid.Text + @"" + Environment.NewLine;
asXML += @"" + txtname.Text + @"" + Environment.NewLine;
asXML += @"" + txtage.Text + @"" + Environment.NewLine;
asXML += @"";
FileStream test= new FileStream("test.xml", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(test);
sw.Write("Hello file system world!");
sw.Close();
test.Close();
It's not creating the test.xml file... Please correct it...
Thanks in advance
Regards,
Samson
|
|
|
|
|
Here i had change the code as
sw.write(asXML);
i got the xml file,but it's not writing the value from textbox.
I'm Getting the folloeing error.
XML document must have a top level element. Error processing resource 'file:///C:/Documents and Settings/sbritto/Desktop/test.xml
Please correct it...
Thanks in advance
With Regards,
Samson
|
|
|
|
|
you're not writing XML. Stop flailing about in the dark, abandon the path of ignorance, and actually do some work to establish that the code you enter stands some semblance of a chance of working.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
samsonx wrote: Please correct it...
Well, I'd recommend you do some reading on XML, and possibly C#. You either are hoping for some sort of magic to happen that has nothing to do with any code that you've written, or you plain have no idea. You've not written any nodes here, this would only work if you magically happened to type the right values into your textboxes to create XML. Either way, as the original guy said, this is horrible code. XmlTextWriter is the class you should be using. I've confirmed that there's tons of info and examples on the web, easily found with your search engine of choice.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: Either way, as the original guy said, this is horrible code.
I'm having fun here
I are troll
|
|
|
|
|
is it possible to have a click event that takes three paramenter i:e
private void MyButton_Click(object sender, EventArgs e,int xyz)
{
}
if yes then how?
thanks
|
|
|
|
|
Yes and no. That not what you wanted to hear, but let me explain;
You can't change the way that a standard button uses to signal a click. Trust me, that's a good thing.
You can make your own button however, and fire your own custom event. You'd have to create a delegate and a matching event.
Throughout the .NET framework you'll find that most events are based on TWO parameters. The first one being the sender, the second one the arguments. That's done for enhanced readability. If you want to send an extra param, then you could derive from EventArgs and pass those.
My apologies for deepening the confusion
I are troll
|
|
|
|
|
It is not possible with Button class, the EventHandler delegate is defined like this:
public delegate void EventHandler(
Object sender,
EventArgs e
)
Regards,
Lev
|
|
|
|
|
To add to what others have said. Assuming you added this parameter, what do you hope it will contain ? Where could it come from and how ?
The way things work in .NET is that there's always two params ( as someone else said ). To clarify, if extra info is needed, a class is used derived from EventArgs, such as MouseEventArgs, send with a mouse event and containing pertinent information. Just for clarity, it would be wise if you create a custom button, that you create a custom event args instead of adding extra parameters to the list.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
how to implement logarithmic functions in asp.net
|
|
|
|
|
I didn't get your Qs.Can you be bit detailed.
elci wrote: functions in asp.net
Always post in right forum.
Cheers!!
Brij
|
|
|
|
|
if i specify log2 base10 i should get the log value which matches the log table
|
|
|
|
|
What do you mean log2 base10, log2 is base 2.
You can use the log static functions defined in Math class:
Math.Log(double a)
Math.Log(double a, double base)
Math.Log10(double a)
Regards,
Lev
|
|
|
|
|
|
You're welcome
Regards,
Lev
|
|
|
|