Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Friends need help here! SQL

Friends need help here! SQL

Scheduled Pinned Locked Moved C#
databasegraphicssysadmintestingbeta-testing
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    krajah10
    wrote on last edited by
    #1

    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.

    J 1 Reply Last reply
    0
    • K krajah10

      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.

      J Offline
      J Offline
      joon vh
      wrote on last edited by
      #2

      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; } }

      K 1 Reply Last reply
      0
      • J joon vh

        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; } }

        K Offline
        K Offline
        krajah10
        wrote on last edited by
        #3

        Tq for reply. Where is my mistake and what to add,im beginer for database connection.

        J 1 Reply Last reply
        0
        • K krajah10

          Tq for reply. Where is my mistake and what to add,im beginer for database connection.

          J Offline
          J Offline
          joon vh
          wrote on last edited by
          #4

          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; } }

          K 1 Reply Last reply
          0
          • J joon vh

            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; } }

            K Offline
            K Offline
            krajah10
            wrote on last edited by
            #5

            Tq for your help...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups