Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ขอโค้ด ล็อกอิน Login Visual C# .NET ใช้ SQL 2008 เป็นฐานข้อมูลค๊า



 

ขอโค้ด ล็อกอิน Login Visual C# .NET ใช้ SQL 2008 เป็นฐานข้อมูลค๊า

 



Topic : 042108



โพสกระทู้ ( 64 )
บทความ ( 0 )



สถานะออฟไลน์




ขอโค้ด Login Visual C# ใช้ SQL 2008 เป็นฐานข้อมูลค๊า

ช่วยด้วยนะค่ะ

__/\__



ใช้ Visual C# 2005 ค่ะ

กับ SQL 2008



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-04-28 09:08:10 By : oomi2830 View : 27755 Reply : 22
 

 

No. 1



โพสกระทู้ ( 64 )
บทความ ( 0 )



สถานะออฟไลน์


ต่อจากข้างบนค่ะ

ใช้ Visual C# 2005 ค่ะ

กับ SQL 2008






Date : 2010-04-28 09:09:49 By : oomi2830
 


 

No. 2



โพสกระทู้ ( 20 )
บทความ ( 0 )



สถานะออฟไลน์


Code (C#)
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


public partial class LoginControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (Session["User"] != null)
        {
            Response.Write("session has valu");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ฐานข้อมูลของคุณ);
        try
        {
            conn.Open();
            string SqlText = "SELECT UserID, Username, Position FROM [User] WHERE Username=@Username AND Password=@Password";
            SqlCommand cmd = new SqlCommand(SqlText, conn);
            cmd.Parameters.AddWithValue("@Username", TextBox1.Text.Trim());
            cmd.Parameters.AddWithValue("@Password", TextBox2.Text.Trim());
            SqlDataReader dr = cmd.ExecuteReader();
            try
            {
                if (dr != null && dr.HasRows == true)
                {
                   // Response.Write("login true");

                    if (dr.Read())
                    {
                        Session["User"] = dr["Username"].ToString();
                        Session["UserID"] = dr["UserID"].ToString();
                        Session["Position"] = dr["Position"].ToString();
                        Session.Timeout = 10;
                    }
                    dr.Close();
                }
                else
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallJs", "alert('Password ไม่ถูกต้องกรูณา Login ใหม่อีกครั้ง');", true);
                }
            }
            finally
            {
                conn.Close();
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
}

Date : 2010-04-28 18:51:31 By : bloodeye
 

 

No. 3



โพสกระทู้ ( 64 )
บทความ ( 0 )



สถานะออฟไลน์


ลองก่อนนะค่ะ
Date : 2010-04-29 09:25:24 By : oomi2830
 


 

No. 4



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์


Application

Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace MSEquipment
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        SqlConnection Conn = new SqlConnection();

        private void frmLogin_Load(object sender, EventArgs e)
        {
            string strConn = DBConnString.strConn;

            if (Conn.State == ConnectionState.Open)
            {
                Conn.Close();
            }
            Conn.ConnectionString = strConn;
            Conn.Open();
        }

        private void cmdLogin_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("SELECT UserName,Password FROM MEMBER");
            sb.Append(" WHERE (UserName=@UserName)");
            sb.Append(" AND (Password=@Password)");

            SqlParameter UserName = new SqlParameter("UserName", SqlDbType.VarChar);
            SqlParameter Password = new SqlParameter("Password", SqlDbType.VarChar);

            string sqlLogin;
            sqlLogin = sb.ToString();

            SqlCommand com = new SqlCommand();
            SqlDataReader dr;

            com.CommandType = CommandType.Text;
            com.CommandText = sqlLogin;
            com.Connection = Conn;
            com.Parameters.Add(UserName).Value = txtUserName.Text;
            com.Parameters.Add(Password).Value = txtPassword.Text;

            dr = com.ExecuteReader();
            if (dr.HasRows)
            {
                frmMain frm = new frmMain();
                frm.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("UserName หรือ Password ที่คุณป้อน ไม่ถูกต้อง !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtUserName.Text = "";
                txtUserName.Focus();
                txtPassword.Text = "";
            }

            dr.Close();
            dr.Dispose();
        }

        private void cmdEnd_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

Date : 2010-04-29 11:10:02 By : worlord
 


 

No. 5



โพสกระทู้ ( 64 )
บทความ ( 0 )



สถานะออฟไลน์


ในฐานข้อมูลมี 2 ฟิลด์ใช่มั้ยค่ะ
มี Username กับ Password
Date : 2010-04-29 12:14:31 By : oomi2830
 


 

No. 6

Guest


เอา Mail มาละกันครับ เดี๋ยวส่ง CODE ให้ ขี้เกียจเขียน
หรือ Mail มาละกัน [email protected]
Date : 2010-04-30 10:27:12 By : wichian
 


 

No. 7



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


---------------------^
--------------------
เขียนหน่อยจะได้ดูด้วย------------------
Date : 2010-05-04 20:27:13 By : simrun810
 


 

No. 8

Guest


ไม่เห็นต้องเขียน copy paste ก็ได้ คนอื่นจะได้ดูด้วย

แต่คนแถวนี้ชอบถามก่อนหา ไม่ต้องก็ได้มั้ง
Date : 2010-05-05 00:37:07 By : แวะมาดู
 


 

No. 9

Guest


ฮ่าๆๆๆๆ
Date : 2011-09-23 19:10:44 By : 8owling
 


 

No. 10

Guest


ขอโค้ด ติดต่อถานข้อมูล SQL ที่สามาดสะแดงรูปออกมาด้วย
Date : 2012-01-12 21:46:26 By : lady M
 


 

No. 11

Guest


Code (C#)
Console.WriteLine("Visual Studio C# 2010");

Date : 2012-09-09 10:41:11 By : Microsoft.Admin
 


 

No. 12

Guest


Code (C#)
textBox1.Text="Text textBox";

Date : 2012-09-09 10:42:59 By : Microsoft.Admin
 


 

No. 13

Guest


รบกวน บอกโค้ด การทำบิล ร้านอาหารให้หน่อยน่ะ ค่ะ เป็น visaul c# ตอ้งส่ง อาจารย์ พรุ่งนี้แล้วค่ะ :"(
Date : 2012-09-23 12:01:34 By : yok
 


 

No. 14

Guest


รบกวน บอกโค้ด การทำบิล ร้านอาหารให้หน่อยน่ะ ค่ะ เป็น visaul c# ตอ้งส่ง อาจารย์ พรุ่งนี้แล้วค่ะ :"(
Date : 2012-09-23 12:02:51 By : yok
 


 

No. 15



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook



Go to : VB.NET/C# Connect to SQL Server Using ADO.NET พื้นฐานกับ SQL Server and ADO.NET
Date : 2012-09-23 15:08:26 By : mr.win
 


 

No. 16

Guest


พี่ค่ะ string strConn = DBConnString.strConn;
มีปัญหาตรง DBConnString ทำยังไงดีค่ะถึงจะแก้ไขได้ค่ะ
Date : 2012-10-07 00:54:18 By : ammary
 


 

No. 17



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
พี่ค่ะ string strConn = DBConnString.strConn;
มีปัญหาตรง DBConnString ทำยังไงดีค่ะถึงจะแก้ไขได้ค่ะ


ตั้งกระทู้ใหม่ครับ
Date : 2012-10-07 08:48:12 By : mr.win
 


 

No. 18

Guest


ddwdew
Date : 2017-05-14 15:20:03 By : aa
 


 

No. 19

Guest


ถ้ามี statusด้วยเขียนยังไงครับ
ถ้า 1 = พนักงาน
2 = ผู้จัดการ
Date : 2017-05-14 15:23:44 By : job
 


 

No. 20

Guest


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;

namespace Hospital
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
DBHospitalDataContext db = new DBHospitalDataContext();
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtUser.Text.Trim() == "" && txtPassword.Text.Trim() == "")
{
MessageBox.Show("กรุณากรอกชื่อผู้ใช้และรหัสผ่าน", "Login ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUser.Focus();
return;
}
if (chkLogin(txtUser.Text, txtPassword.Text))
{
MDIParent1 h = new MDIParent1();
h.Username = txtUser.Text.Trim();
h.Show();
this.Hide();
}
}
private bool chkLogin(string user, string pass)
{
try
{
var q = from e in db.Employees
where e.UserName == txtUser.Text
&& e.Pass == txtPassword.Text
select e;

if (q.Any())
{
MessageBox.Show("ยินดีต้อนรับเข้าสู่ระบบ", "Login ถูกต้อง", MessageBoxButtons.OK, MessageBoxIcon.Information);

return true;
}
else
{
MessageBox.Show("ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง", "Login ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
clearForm();
return false;
}
}
catch { }

}
private void clearForm()
{
txtUser.Text = "";
txtPassword.Text = "";
txtUser.Focus();
}
}
}
Date : 2018-02-08 16:50:01 By : จ่อยผู้เร้าใจ
 


 

No. 21

Guest


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;

namespace Hospital
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }
        DBHospitalDataContext db = new DBHospitalDataContext();
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUser.Text.Trim() == "" && txtPassword.Text.Trim() == "")
            {
                MessageBox.Show("กรุณากรอกชื่อผู้ใช้และรหัสผ่าน", "Login ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUser.Focus();
                return;
            }
            if (chkLogin(txtUser.Text, txtPassword.Text))
            {
                MDIParent1 h = new MDIParent1();
                h.Username = txtUser.Text.Trim();
                h.Show();
                this.Hide();
            }
        }
        private bool chkLogin(string user, string pass)
        {
            try
            {
                var q = from e in db.Employees
                        where e.UserName == txtUser.Text
                        && e.Pass == txtPassword.Text
                        select e;

                if (q.Any())
                {
                    MessageBox.Show("ยินดีต้อนรับเข้าสู่ระบบ", "Login ถูกต้อง", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    return true;
                }
                else
                {
                    MessageBox.Show("ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง", "Login ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    clearForm();
                    return false;
                }
            }
            catch { }

        }
        private void clearForm()
        {
            txtUser.Text = "";
            txtPassword.Text = "";
            txtUser.Focus();
        }

Date : 2018-02-08 16:55:26 By : จ่อยผู้เร้าใจ
 


 
12121
Date : 2022-03-15 02:55:21 By : น้ำใจ มะลิวัน
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอโค้ด ล็อกอิน Login Visual C# .NET ใช้ SQL 2008 เป็นฐานข้อมูลค๊า
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่