当前位置:编程学习 > C#/ASP.NET >>

求帮助

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>
/// EditClass 的摘要说明
/// </summary>
public class EditClass
{
public EditClass()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
    public bool Execsql(string sqlstr)
    {
        string connstring = ConfigurationManager.AppSettings["connStr"];
        SqlConnection conn = new SqlConnection(connstring );
        conn.Open();
        SqlCommand comd = new SqlCommand(sqlstr ,conn );
        try
        {
            comd.ExecuteNonQuery(); 
            conn.Close();

        }
        catch (Exception e)
        {
            
            return false;
        }
        return true;
    
    }
    public SqlConnection GetConn()
    { 
     string connstring=ConfigurationManager.AppSettings["connStr"];
     SqlConnection conn = new SqlConnection(connstring);
     conn.Open();
     return conn;
    }
    public DataSet GetDataSet(string sqlstring, string mytb1)
    {
        DataSet ds = new DataSet();
        SqlDataAdapter sda = new SqlDataAdapter(sqlstring,GetConn );
        sda.Fill(ds,"mytb1");
        return ds;
    
    }
}



编译器错误信息: CS1502: 与“System.Data.SqlClient.SqlDataAdapter.SqlDataAdapter(string, string)”最匹配的重载方法具有一些无效参数

--------------------编程问答-------------------- 给个小例子

        //数据库连接字符串(web.config来配置)
        public static string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        /// <summary>
        /// 执行查询语句,返回DataSet
        /// </summary>
        /// <param name="SQLString">查询语句</param>
        /// <returns>DataSet</returns>
        public static DataSet Query(string SQLString)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                DataSet ds = new DataSet();
                try
                {
                    connection.Open();
                    SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
                    command.Fill(ds, "ds");
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    throw new Exception(ex.Message);
                }
                return ds;
            }
        }
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,