I am writing a code that will login the user then one they are logged in they will enter in other information in textboxes.

I wanted to know how to check that the username, password and ID match what is in a sql database. Also once it goes through how to output all of that into one textbox that will ultimately go to a txt file. I have all the other textboxes done just need those.

if you need other info let me know.

thank you!

ofcourse yes, pls show us what have you done, paste your code here.
Where exactly are u facing the problem.?
you must have the similar columns of a table in the DB,
have a data access layer which wil talk to the DB to fetch values of username and password, if there is a value returning, it is true, the password has been validated for a username, if there is novalue returned, then the username and password does not match.
this is the overall view.

Also once it goes through how to output all of that into one textbox that will ultimately go to a txt file. I have all the other textboxes done just need those.


do you mean you just need to put the login details into a text box once they have been checked ?

the method below returns a boolean value, checks that the login details exist in the database executing an SQL statement to return number of rows that contain the login details provided by the user and return. if there the row count is 1 or more the method returns true and the user is logged in if the row count is 0 it returns false and login fails (change the variables to suite your needs).

public bool getCridentials(string _username, string _password)
        {
            //Sets the value of booliean variable called valid to false
            bool valid = false;

            //Sql statement that counts the amount of rows in the OSDE_Users table where the username and password fields are the same as those entered by the user
            string loginSQL = "SELECT COUNT(Logon) FROM STARWATCH.dbo.OSDE_Users WHERE Username = '" + _username + "' AND Password = '" + _password + "'";

            //Sql command that executes the Sql statement
            SqlCommand cmd = new SqlCommand(loginSQL, db.Connect());

            try
            {
                //int variable that stores the result of the Sql statement
                int rowCount = Convert.ToInt32(cmd.ExecuteScalar());
                //Executed if the value of rowCount is greater than or equal to 1
                if (rowCount >= 1)
                {
                    //Sets the value of valid variable to true
                    valid = true;
                }
                //Executed if the value of rowCount is less than or equal to 0
                else if (rowCount <= 0)
                {
                    //Sets the value of valid variable to false
                    valid = false;
                }
            }
            catch
            {
            }
            //Returns the value of valid
            return valid;
        }

and this should be what you need to get the data out of the database and into the textboxes (change the statements ect yourself to get correct data)

public void getInfo(string _username, string _password)
        {

            string selectAllSql = "Select * FROM TableName WHERE userName = '" + _username + "' AND password = '" + _password + "'";

            // db.connect is the method to connect to my database you will need on is you havent already got one
            SqlCommand cmd = new SqlCommand(selectAllSql, db.Connect());

            //Creates SQLdatareader
            SqlDataReader reader;

            try
            {
                //Reads the result of cmd command
                reader = cmd.ExecuteReader();
                //Executes contents while there is data to available to read
                while (reader.Read())
                {
                    //Stores int variable in int property in ObjectTypeState class
                    textBox1.Text = reader["userName"].ToString();

                    textBox2.Text = reader["password"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw (new Exception("" + ex));
            }
        }

hope this helps

Sorry that was confusing. I meant once all the information is onto the form I want to output that to a text file. Either one already made or one that creates itself with the information.

ofcourse yes, pls show us what have you done, paste your code here.
Where exactly are u facing the problem.?
you must have the similar columns of a table in the DB,
have a data access layer which wil talk to the DB to fetch values of username and password, if there is a value returning, it is true, the password has been validated for a username, if there is novalue returned, then the username and password does not match.
this is the overall view.

Here is what I have so far.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Data.SqlClient;

namespace exporter
{
    public partial class SGML_Exporter : Form
    {
        public SGML_Exporter()
        {
            InitializeComponent();
        }

      
      
            private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'import_logDataSet.DB_tables' table. You can move, or remove it, as needed.
            this.dB_tablesTableAdapter.Fill(this.import_logDataSet.DB_tables);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            save.ShowDialog();
        }

        private void save_FileOk(object sender, CancelEventArgs e)
        {
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //Clears all text in text box
            id.Clear();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            
            string str = @"";
            Process process = new Process();
            process.StartInfo.FileName = str;
            process.Start(); 
        }

        private void id_KeyPress(object sender, KeyPressEventArgs e)
        {
           
            char ch = e.KeyChar;
            if (!Char.IsDigit(ch) && ch != 8 && ch != 13 && e.KeyChar < 65 || e.KeyChar > 122)
            {
                e.Handled = true;
            }

            
        }
        private void OutputBox_TextChanged(object sender, EventArgs e)
        {
      
        }

        private void UserName_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void Help_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.google.com");
            Help.LinkVisited = true;
        }
    }
}
This article has been dead for over six months. Start a new discussion instead.