用sql2005的数据库
说说思路,尽量详细点。
用sql2005的数据库
说说思路,尽量详细点。
public string STR_CONN = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString.ToString();
/// <summary>
/// 查询
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public DataSet Query(string sql)
{
using (SqlConnection conn = new SqlConnection(STR_CONN))
{
using (SqlDataAdapter sda = new SqlDataAdapter(sql, STR_CONN))
{
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds;
}
}
}
}
/// <summary>
/// 针对增删改操作
/// </summary>
/// <param name="sql"></param>
/// <param name="param"></param>
/// <returns></returns>
public int TSG(string sql, SqlParameter[] param)
{
SqlConnection conn = new SqlConnection(STR_CONN);
SqlCommand cmd = new SqlCommand(sql, conn);
if (param != null && param.Length > 0)
{
foreach (SqlParameter p in param)
{
cmd.Parameters.Add(p);
}
}
try
{
conn.Open();
return cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
// tran.Rollback();
throw new Exception(ex.Message);
}
finally
{
conn.Close();
}
}
用ajax调用web服务,然后在web服务里面连接数据库啊
web服务就是webservice或者.ashx的文件
sqlconnection con=newsqlconnection("server=.,uid=;pwd=;database=")
sqlcommand cmd=new sqlcommand("select *from table",con)
con.open();
datatable dt=new datatable();
有点忘记了 我去看看书再来回答 呵呵