Friends need help here! SQL
-
My password validater window form cant read the password from database that have been set please help me; database name=testing table name = table1 field name=password the default password I set in password is "ABCD" below is the coding: ///////////////////// using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Data.SqlClient; using System.Windows.Forms; namespace cuba3 { public partial class Form1 : Form { Form2 form3 = new Form2(); public Form1() { InitializeComponent(); } private void button1_Click(object sender,EventArgs e) { string connectionString = "server = P-III; database =testing;uid=sa;pwd=;"; SqlConnection conn = new SqlConnection(connectionString); string commandString = "SELECT password from table1"; SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, conn); string strEnteredPassword = textBox1.Text; if (strEnteredPassword == commandString) { this.Hide(); form3.ShowDialog(); } else { MessageBox.Show("Wrong password entered"); this.Close(); } } } } tq in Advance.
-
My password validater window form cant read the password from database that have been set please help me; database name=testing table name = table1 field name=password the default password I set in password is "ABCD" below is the coding: ///////////////////// using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Data.SqlClient; using System.Windows.Forms; namespace cuba3 { public partial class Form1 : Form { Form2 form3 = new Form2(); public Form1() { InitializeComponent(); } private void button1_Click(object sender,EventArgs e) { string connectionString = "server = P-III; database =testing;uid=sa;pwd=;"; SqlConnection conn = new SqlConnection(connectionString); string commandString = "SELECT password from table1"; SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, conn); string strEnteredPassword = textBox1.Text; if (strEnteredPassword == commandString) { this.Hide(); form3.ShowDialog(); } else { MessageBox.Show("Wrong password entered"); this.Close(); } } } } tq in Advance.
krajah1984 wrote:
if (strEnteredPassword == commandString)
wanting something to work doens't make it so ;) you have to actually execute the command, and then read it with a reader, or alternatively fill a dataset with the results and read them from there. Look up some ADO.NET tutorials. What you are doing right now, and where it fails, is easily explained:
krajah1984 wrote:
string commandString = "SELECT password from table1"; SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, conn); string strEnteredPassword = textBox1.Text; if (strEnteredPassword == commandString)
you are checking if "ABCD" is equal to "SELECT password from table1".
Visual Studio can't evaluate this, can you?
public object moo { __get { return moo; } __set { moo = value; } }
-
krajah1984 wrote:
if (strEnteredPassword == commandString)
wanting something to work doens't make it so ;) you have to actually execute the command, and then read it with a reader, or alternatively fill a dataset with the results and read them from there. Look up some ADO.NET tutorials. What you are doing right now, and where it fails, is easily explained:
krajah1984 wrote:
string commandString = "SELECT password from table1"; SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, conn); string strEnteredPassword = textBox1.Text; if (strEnteredPassword == commandString)
you are checking if "ABCD" is equal to "SELECT password from table1".
Visual Studio can't evaluate this, can you?
public object moo { __get { return moo; } __set { moo = value; } }
-
I told you what your mistake was. You can't just compare a command to the desired result. You have to execute the command, get the results, and then compare these. Pleae follow this tutorial, it will help you a lot probably: http://www.codeproject.com/cs/database/DatabaseAcessWithAdoNet1.asp
Visual Studio can't evaluate this, can you?
public object moo { __get { return moo; } __set { moo = value; } }
-
I told you what your mistake was. You can't just compare a command to the desired result. You have to execute the command, get the results, and then compare these. Pleae follow this tutorial, it will help you a lot probably: http://www.codeproject.com/cs/database/DatabaseAcessWithAdoNet1.asp
Visual Studio can't evaluate this, can you?
public object moo { __get { return moo; } __set { moo = value; } }