📄 edit.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// edit 的摘要说明
/// </summary>
public class edit
{
public edit()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public int check(string jibie, string username, string pass)
{
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
///String cmdText = "select * from user ";
string cmdText = "select count(*) from users where username='" + username + "' and password='" + pass + "' and jibie='" + jibie + "' ";
///创建Command
SqlCommand myCommand = new SqlCommand(cmdText, myConnection);
SqlDataReader dr=null;
///定义返回值
int nResult = -1;
try
{
///打开链接
myConnection.Open();
///执行SQL语句
nResult = (int)myCommand.ExecuteScalar();
}
catch (SqlException ex)
{
///抛出异常
throw new Exception(ex.Message, ex);
}
finally
{ ///关闭链接
myConnection.Close();
}
///返回nResult
return nResult;
}
public DataSet GetCustomertypefo(string table)
{
///创建链接
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
///创建Command
/// SqlCommand myCommand = new SqlCommand("select * from " + table + "", myConnection);//table 为各个表
SqlDataAdapter myda = new SqlDataAdapter("select * from " + table + "", myConnection);
///定义DataSet
DataSet dr = new DataSet("typeDataset");
try
{
///打开链接
myConnection.Open();
///读取数据
myda.Fill(dr, "ctype");
// dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
///抛出异常
throw new Exception(ex.Message, ex);
}
finally
{
myConnection.Close();
}
///返回DataSet
return dr;
}
public SqlDataReader GetSingleCTCode(String cmdText)
{
SqlConnection myconnect = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
SqlCommand mycommand = new SqlCommand(cmdText, myconnect);
SqlDataReader dr = null;
try
{
myconnect.Open();
dr = mycommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException e)
{
throw new Exception(e.Message, e);
}
return dr;
}
public DataSet GetInfro(string cmdtext)
{
///创建链接
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
///创建Command
/// SqlCommand myCommand = new SqlCommand("select * from " + table + "", myConnection);//table 为各个表
SqlDataAdapter myda = new SqlDataAdapter(cmdtext, myConnection);
///定义DataSet
DataSet dr = new DataSet("typeDataset");
try
{
///打开链接
myConnection.Open();
///读取数据
myda.Fill(dr, "ctype");
// dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
///抛出异常
throw new Exception(ex.Message, ex);
}
finally
{
myConnection.Close();
}
///返回DataSet
return dr;
}
public int execute(string content)
{
SqlConnection myconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
SqlCommand mycommand = new SqlCommand(content, myconnection);
int nResult = -1;
try
{
///打开链接
myconnection.Open();
///执行SQL语句
nResult = mycommand.ExecuteNonQuery();
}
catch (SqlException ex)
{
///抛出异常
int length = ex.Message.Length;
string ec;
if (ex.Message.Contains("\r\n"))
{
ec=ex.Message.Remove(length - 10);
}
else
{
ec = ex.Message.Remove(length - 1);
}
System.Web.HttpContext.Current.Response.Redirect("error.aspx?ec=" + ec);
// throw new Exception(ex.Message, ex);
}
finally
{ ///关闭链接
myconnection.Close();
}
///返回nResult
return nResult;
}
public int insert(string cmd1, string cmd2)
{
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
myConnection.Open();
SqlTransaction tran = myConnection.BeginTransaction();//开始进行交易处理
SqlCommand com = new SqlCommand();
com.Connection = myConnection;
com.Transaction = tran;
int nResult = -1;
try
{
com.CommandText = cmd1;
nResult= com.ExecuteNonQuery();
com.CommandText = cmd2;
nResult = com.ExecuteNonQuery();
tran.Commit();
}
catch (SqlException ex)
{
tran.Rollback();
int length = ex.Message.Length;
string ec;
if (ex.Message.Contains("\r\n"))
{
ec = ex.Message.Remove(length - 10);
}
else
{
ec = ex.Message.Remove(length - 1);
}
System.Web.HttpContext.Current.Response.Redirect("error.aspx?ec=" + ec);
}
finally
{
myConnection.Close();
}
return nResult;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -