|
 |
|
ขอโค้ด asp.net c# การทำ Log in โดยใช้ Access หน่อยค่ะ ขอบคุณค่ะ |
|
 |
|
|
 |
 |
|
ต่างกันนิดหน่อยเองครับ แค่ใช้ OleDb และแก้ไข Connection String ท่านั้น ลองดูบทความนี้ครับ ใช้ .Net กับ Access
Code (C#)
private void btnLogin_Click(object sender, EventArgs e)
{
OleDbConnection objConn = new OleDbConnection();
OleDbCommand objCmd = new OleDbCommand();
string strConnString = null;
string strSQL = null;
string directory = Path.GetDirectoryName(Application.ExecutablePath);
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + directory + "\\database.mdb;Jet OLEDB:Database Password=;";
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 OleDbCommand(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;
}
ทำ Form Login บน Windows Form Application ง่าย ๆ ด้วย VB.NET และ C#
|
 |
 |
 |
 |
Date :
2013-12-27 09:22:09 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะขอลองก่อนนะค่ะ
|
 |
 |
 |
 |
Date :
2013-12-27 15:07:18 |
By :
oon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ค่ะลองแก้แล้วต่ะ แต่ปรากฎว่าติดตรง
objCmd.Parameters.Add("@sView", SqlDbType.Integer).Value = 0;
objCmd.Parameters.Add("@sReply", SqlDbType.Integer).Value = 0;
SqlDbType ใช้กับ Integer ไม่ได้ ไม่ทราบว่าต้องแก้ยังไงค่ะ ขอบคุณค่ะ
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Text;
namespace AspNetWebboardCS
{
public partial class NewQuestion : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
SqlConnection objConn = null;
StringBuilder strSQL = new StringBuilder();
SqlCommand objCmd = null;
string strConnString = null;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\database.mdb";
objConn = new SqlConnection(strConnString);
objConn.Open();
//*** Insert Reply ***'
strSQL.Append(" INSERT INTO webboard (CreateDate,Question,Details,Name,[View],Reply) ");
strSQL.Append(" VALUES ");
strSQL.Append(" (@sCreateDate,@sQuestion,@sDetails,@sName,@sView,@sReply) ");
objCmd = new SqlCommand(strSQL.ToString(), objConn);
objCmd.Parameters.Add("@sCreateDate", SqlDbType.Date).Value = DateTime.Now.ToString();
objCmd.Parameters.Add("@sQuestion", SqlDbType.VarChar).Value = this.txtQuestion.Text;
objCmd.Parameters.Add("@sDetails", SqlDbType.VarChar).Value = this.txtDetails.Text;
objCmd.Parameters.Add("@sName", SqlDbType.VarChar).Value = this.txtName.Text;
objCmd.Parameters.Add("@sView", SqlDbType.Integer).Value = 0;
objCmd.Parameters.Add("@sReply", SqlDbType.Integer).Value = 0;
objCmd.ExecuteNonQuery();
objConn.Close();
objConn = null;
Response.Redirect("Webboard.aspx");
}
}
}
|
 |
 |
 |
 |
Date :
2013-12-28 20:26:38 |
By :
oon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|