What's new

Closed c# visual studio 2015 using sql server

Status
Not open for further replies.

moimoi018

Enthusiast
Joined
Aug 26, 2019
Posts
1
Reaction
2
Points
63
Capture.PNG

boss pa help naman sa visual studio 2015 na stuck ako sa login form. wala po akong makita na error pero po nag iinvalid yung login ko
Login form
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MiniPayroll
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            Connection con = new Connection();
            con.dataGet("Select * from [User] Where UserName = '"+txtUserName.Text +"' and Password = ' " + txtPassword.Text + " ' ");
            DataTable dt = new DataTable();
            con.sda.Fill(dt);
            if (dt.Rows.Count > 0)
            {

                this.Hide();
                frmMain frm = new frmMain();
                frm.Show();

            }
            else
            {
                MessageBox.Show("Invalid Username & Password..!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}

tas gumamit po ako ng class para sa sql server ko pa help naman po.. tnk u

C#:
using System;
using System.Data.SqlClient;

namespace MiniPayroll
{
    class Connection
    {
        public SqlConnection con;
        public SqlCommand cmd;
        public SqlDataAdapter sda;
        public string pkk;

        public void connection()
        {
            con = new SqlConnection(@"Data Source=OPPO; Initial Catalog=MiniPayroll;Integrated Security=True");
            con.Open();
        }
        public void dataSend(string SQL)
        {
            try
            {
                connection();
                cmd = new SqlCommand(SQL, con);
                cmd.ExecuteNonQuery();

                pkk = "";
            }
            catch (Exception)
            {
                pkk = "Please Check Your Data";
            }
            con.Close();
        }
        public void dataGet(string SQL)
        {
            try
            {
                connection();
                sda = new SqlDataAdapter(SQL, con);
            }
            catch (Exception)
            {

            }
        }

    }
}
 

Attachments

Last edited:
Status
Not open for further replies.

Similar threads

Back
Top