在app_code中新增類,取名為TBOperate.cs,內容如下using System;using System.Collections.Generic;using System.Text;using System.Data.SqlClient;using System.Data;namespace DesignTBOperate{ public class TBOperate { protected SqlConnection connection = null; public TBOperate() { string databasestr = System.Configuration.ConfigurationSettings.AppSettings["connectionStrings"]; connection = new SqlConnection(databasestr); } public TBOperate(string iConnectionString) { connection = new SqlConnection(iConnectionString); } public Boolean hasUser(string nameField, string username, string pswField,string Psw,string Tbname) { string sql = "Select Count(*) From " + Tbname + " Where " + nameField + "="" + username + "" And " + pswField + "="" + Psw + """; if (isData(sql) > 0) return true; else return false; } }}在頁面對應CS檔案中的呼叫方法:using DesignTBOperate;TBOperate myOperate = new TBOperate();if (myOperate.hasUser("name",Textbox_name.text,"psw",TextBox2_psw.text,"users")){//登陸成功}else{//登陸失敗}
在app_code中新增類,取名為TBOperate.cs,內容如下using System;using System.Collections.Generic;using System.Text;using System.Data.SqlClient;using System.Data;namespace DesignTBOperate{ public class TBOperate { protected SqlConnection connection = null; public TBOperate() { string databasestr = System.Configuration.ConfigurationSettings.AppSettings["connectionStrings"]; connection = new SqlConnection(databasestr); } public TBOperate(string iConnectionString) { connection = new SqlConnection(iConnectionString); } public Boolean hasUser(string nameField, string username, string pswField,string Psw,string Tbname) { string sql = "Select Count(*) From " + Tbname + " Where " + nameField + "="" + username + "" And " + pswField + "="" + Psw + """; if (isData(sql) > 0) return true; else return false; } }}在頁面對應CS檔案中的呼叫方法:using DesignTBOperate;TBOperate myOperate = new TBOperate();if (myOperate.hasUser("name",Textbox_name.text,"psw",TextBox2_psw.text,"users")){//登陸成功}else{//登陸失敗}