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. How to connect My Sql Database to compare string from database.

How to connect My Sql Database to compare string from database.

Scheduled Pinned Locked Moved C#
databasecsharpsql-servergraphicssysadmin
3 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

    Hello friends need help here.. Before this I have learn to create password validating form.Which is user have to key in password to enter another form. The password is default that have set in the coding.Now I need help how to connect to MY Sql database from C# from and compare the password that already I set in MY Sql database,table name Security and Field name password and the password is "ABCD".I dont know how to use SQL server 2005. Below are the coding for the first form that validate to enter to form2. ////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace cubaan1 { public partial class Form1 : Form { Form2 form1 = new Form2(); public Form1() { InitializeComponent(); } private void textBox1_TextChanged(object sender, EventArgs e) { textBox1.PasswordChar = '*'; //Masking Char textBox1.MaxLength = 14;//Max Length is 14 } private void button1_Click(object sender, EventArgs e) { string strDefaultPassword = "security"; //Keep the default password string strEnteredPassword = textBox1.Text; if (strEnteredPassword == strDefaultPassword) { this.Hide(); form1.ShowDialog(); } else { MessageBox.Show("Wrong password entered"); this.Close(); } } } } ////////////////////////////////////////////////////////// How to change this to connect to MY Sql Database and compare the password from the database. Tq in advance......

    S 1 Reply Last reply
    0
    • K krajah10

      Hello friends need help here.. Before this I have learn to create password validating form.Which is user have to key in password to enter another form. The password is default that have set in the coding.Now I need help how to connect to MY Sql database from C# from and compare the password that already I set in MY Sql database,table name Security and Field name password and the password is "ABCD".I dont know how to use SQL server 2005. Below are the coding for the first form that validate to enter to form2. ////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace cubaan1 { public partial class Form1 : Form { Form2 form1 = new Form2(); public Form1() { InitializeComponent(); } private void textBox1_TextChanged(object sender, EventArgs e) { textBox1.PasswordChar = '*'; //Masking Char textBox1.MaxLength = 14;//Max Length is 14 } private void button1_Click(object sender, EventArgs e) { string strDefaultPassword = "security"; //Keep the default password string strEnteredPassword = textBox1.Text; if (strEnteredPassword == strDefaultPassword) { this.Hide(); form1.ShowDialog(); } else { MessageBox.Show("Wrong password entered"); this.Close(); } } } } ////////////////////////////////////////////////////////// How to change this to connect to MY Sql Database and compare the password from the database. Tq in advance......

      S Offline
      S Offline
      Stanciu Vlad
      wrote on last edited by
      #2

      In the validation procedure (button1_Click) connect to the mysql database with a special driver (either odbc or a dedicated one from the mysql site) - check http://www.connectionstrings.com/[^] for aditional info. Use ado.net to retrive the password for your user (dataTable, dataTableAdaptor and other stuff like this - check articles for this on codeproject). The database querry should return only one value (the password) for the specified user. And olso, try to use parameters with regex in the querry to aviod insertion attacks. Good luck.

      protected internal static readonly ... and I wish the list could continue ...

      K 1 Reply Last reply
      0
      • S Stanciu Vlad

        In the validation procedure (button1_Click) connect to the mysql database with a special driver (either odbc or a dedicated one from the mysql site) - check http://www.connectionstrings.com/[^] for aditional info. Use ado.net to retrive the password for your user (dataTable, dataTableAdaptor and other stuff like this - check articles for this on codeproject). The database querry should return only one value (the password) for the specified user. And olso, try to use parameters with regex in the querry to aviod insertion attacks. Good luck.

        protected internal static readonly ... and I wish the list could continue ...

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

        Can you show me where to put the coding , I can understand. Tq very much.

        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