System.Web.UI.WebControls.SqlDataSource”是“类型”,但此处被当做“变量”来使
源代码usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem...
源代码using System;
using System.Data;
using System.Configuration;
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;
/// <summary>
/// dataOperate 的摘要说明
/// </summary>
public class dataOperate
{
public static SqlConnection con;
public dataOperate()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//执行添加,删除,插入操作
public static bool execSQL(string sql)
{
SqlConnection con = createCon(); //创建连接对象
con.Open();
SqlCommand com = new SqlCommand(sql, con);
try
{
com.ExecuteNonQuery(); //执行SQL语句
con.Close(); //关闭连接对象
}
catch (Exception e)
{
con.Close();
return false; //执行失败返回false
}
return true; //执行成功返回true
}
//查找记录是否存在
public static bool seleSQL(string sql)
{
int i;
SqlConnection con = createCon(); //创建连接对象
con.Open();
SqlCommand com = new SqlCommand(sql, con);
try
{
i = (int)com.ExecuteScalar();
con.Close();
}
catch (Exception e)
{
con.Close();
return false;
}
//大于0存在
if (i > 0)
{
return true;
}
else
{
return false;
}
}
//查找并返回多行数据
public static DataSet getDataset(string aql, string table)
{
SqlConnection con = createCon();
con.Open();
DataSet ds;
SqlDataAdapter sda = new SqlDataAdapter(SqlDataSource, con);
ds = new DataSet();
sda.Foll(ds, table);
return ds;
}
//查找并返回一条数据
public static SqlDataReader getRow(string sql)
{
SqlConnection con = new createCon();
con.Open();
SqlCommand com = new SqlCommand(sql, con);
return com.ExecuteReader();
}
//创建数据库的链接
public static SqlConnection createCon()
{
con = new SqlConnection("server=.;database=db_WL;uid=sa;pwd=;");
return con;
}
} 展开
using System.Data;
using System.Configuration;
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;
/// <summary>
/// dataOperate 的摘要说明
/// </summary>
public class dataOperate
{
public static SqlConnection con;
public dataOperate()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//执行添加,删除,插入操作
public static bool execSQL(string sql)
{
SqlConnection con = createCon(); //创建连接对象
con.Open();
SqlCommand com = new SqlCommand(sql, con);
try
{
com.ExecuteNonQuery(); //执行SQL语句
con.Close(); //关闭连接对象
}
catch (Exception e)
{
con.Close();
return false; //执行失败返回false
}
return true; //执行成功返回true
}
//查找记录是否存在
public static bool seleSQL(string sql)
{
int i;
SqlConnection con = createCon(); //创建连接对象
con.Open();
SqlCommand com = new SqlCommand(sql, con);
try
{
i = (int)com.ExecuteScalar();
con.Close();
}
catch (Exception e)
{
con.Close();
return false;
}
//大于0存在
if (i > 0)
{
return true;
}
else
{
return false;
}
}
//查找并返回多行数据
public static DataSet getDataset(string aql, string table)
{
SqlConnection con = createCon();
con.Open();
DataSet ds;
SqlDataAdapter sda = new SqlDataAdapter(SqlDataSource, con);
ds = new DataSet();
sda.Foll(ds, table);
return ds;
}
//查找并返回一条数据
public static SqlDataReader getRow(string sql)
{
SqlConnection con = new createCon();
con.Open();
SqlCommand com = new SqlCommand(sql, con);
return com.ExecuteReader();
}
//创建数据库的链接
public static SqlConnection createCon()
{
con = new SqlConnection("server=.;database=db_WL;uid=sa;pwd=;");
return con;
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询