日期:2014-05-17  浏览次数:20514 次

DB类
using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;
using System.Data;
/// <summary>
///DB 的摘要说明
/// </summary>
public class DB
{
    public SqlConnection con = new SqlConnection();
    public SqlCommand cmd;
    public DataSet ds = new DataSet();
    public SqlDataAdapter sda;
    public string GetConnectionstring()
    {
        string constr = System.Configuration.ConfigurationManager.AppSettings.Get(0).ToString();
        return constr;
    }
    public DataSet GetDataTableBySql(string sqlstr)
    {
        ds.Clear();
        con.ConnectionString = GetConnectionstring();
        sda = new SqlDataAdapter(sqlstr,con);
        sda.Fill(ds);
        return ds;
    
    }
    public Boolean UpdateDataBySql(string sqlstr)
    {
        con.ConnectionString = GetConnectionstring();
        cmd = new SqlCommand(sqlstr,con);
        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            return true;
        }
        catch (SqlException)
        {
            con.Close();
            return false;
        }
             
    
    }
}
请问这个DB有没有写错,如果没有的话给我讲解一些思路,谢谢!

------解决方案--------------------


    try
        {
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            return true;
        }
        catch (SqlException)
        {