|
 |
|
มีวิธีเช็คค่า textBox ว่าตรงกับ database มั้ยคับ ช่วยทีคับ..... C#.net นะคับ |
|
 |
|
|
 |
 |
|
Code (C#)
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.Data.SqlClient;
using System.IO;
namespace LoginFormCS
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection objConn = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
string strConnString = null;
string strSQL = null;
strConnString = "Server=localhost;UID=sa;PASSWORD=;Database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
objConn.ConnectionString = strConnString;
objConn.Open();
int intNumRows = 0;
strSQL = "SELECT COUNT(*) FROM member WHERE Username = '" + this.txtUsername.Text + "' AND Password = '" + this.txtPassword.Text + "' ";
objCmd = new SqlCommand(strSQL, objConn);
intNumRows = Convert.ToInt32(objCmd.ExecuteScalar());
if (intNumRows > 0)
{
frmMain frm = new frmMain();
frm._strUser = this.txtUsername.Text;
frm.LoadInfor();
frm.Show();
this.Hide();
}
else
{
MessageBox.Show("Username or Password Incorrect");
}
objConn.Close();
objConn = null;
}
private void btnClose_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Exit application?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Application.Exit();
}
}
}
}
Go to : VB.NET/C# Connect to SQL Server Using ADO.NET พื้นฐานกับ SQL Server and ADO.NET
|
 |
 |
 |
 |
Date :
2012-07-09 06:31:13 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|