| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1471 人关注过本帖
标题:用户代码未处理SqlException 列名AreaId无效
只看楼主 加入收藏
王钱
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-3-16
收藏
 问题点数:0 回复次数:1 
用户代码未处理SqlException 列名AreaId无效
using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.Sql;

namespace Fishing.App_Code
{
    public class SQLServerOperation
    {
        protected string SQL;
        SqlConnection conn = new SqlConnection(ConnStr);
        private static string ConnStr = MakeConnStr();

        //拼接形成数据库连接字符串
        public static string MakeConnStr()
        {
            //下面为测试数据库连接
            string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            return connectionString;
        }
        public DataTable Select_DT(string sql, string DataTableName)
        {
            //输入标准SQl语句,返回DataTable类型数据           
            conn.Open();
            SQL = sql;
            SqlDataAdapter DA = new SqlDataAdapter(SQL, conn);
            DataTable DT = new DataTable();
            DT.TableName = DataTableName;
            DA.Fill(DT);
            conn.Close();
            return DT;
           
        }
        public DataSet Select_DS(string sql, string DataTableName)
        {
            //输入标准SQl语句,返回DataSet类型数据
            conn.Open();
            SQL = sql;
            SqlDataAdapter da = new SqlDataAdapter(SQL, conn);
            DataTable DT = new DataTable();
            da.Fill(DT);
            DataSet DS = new DataSet();
            DS.Tables.Add(DT);
            conn.Close();
            return DS;
        }
        public string Insert_SQL(string sql, string DataTableName)
        {
            //将数据插入数据表,输入标准SQL语句,返回成功插入行数
            
            conn.Open();
            SQL = sql;
            SqlCommand CMD = new SqlCommand(sql, conn);
            
            int CNT = CMD.ExecuteNonQuery();
            conn.Close();
            return CNT.ToString();
        }
        public string Insert_SQL_ReturnId(string sql, string DataTableName)
        {
            conn.Open();
            SqlCommand CMD = new SqlCommand(sql, conn);
            int CNT = CMD.ExecuteNonQuery();
            conn.Close();
            return CNT.ToString();
        }
        public void Update_SQL(string sql, string DataTableName)
        {
            //更新数据表,输入标准SQL语句,返回成功插入行数
            conn.Open();
            SQL = sql;
            SqlCommand CMD = new SqlCommand(sql, conn);
            
            int CNT = CMD.ExecuteNonQuery();
            conn.Close();
            
        }
        public void Delete_SQL(string sql, string DataTableName)
        {
            conn.Open();
            SQL = sql;
            SqlCommand CMD = new SqlCommand(sql, conn);

            int CNT = CMD.ExecuteNonQuery();
            conn.Close();
        }
        public int CNT_SQL(string sql, string DataTableName)
        {
            //将数据插入数据表,输入标准SQL语句,返回成功插入行数
            conn.Open();
            SqlCommand CMD = new SqlCommand(sql,conn);
            SqlDataAdapter DA = new SqlDataAdapter(sql, conn);
            DataTable DT = new DataTable();
            DA.Fill(DT);
            int CNT = DT.Rows.Count;            
            conn.Close();
            return CNT;
        }
        public string getUserIdByName(string name)
        {        
            DataTable dt=Select_DT("select UserId from SSC_Users where UserName='" + name + "'", "SSC_Users");
            int count=dt.Rows.Count;
            if (count > 0)
            {
                return dt.Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }
        public string getUserNameById(string id)
        {
            Guid UserId = new Guid(id);
            DataTable dt=this.Select_DT("select UserName from SSC_Users where UserId='" + UserId + "'", "SSC_Users");
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }
        public string getTopicNameById(string id)
        {
            Guid TopicId = new Guid(id);
            return this.Select_DT("select TopicName from SSC_Topics where TopicId='" + TopicId + "'", "SSC_Topics").Rows[0][0].ToString();
        }
        public string getTopicIdByName(string name)
        {
            return this.Select_DT("select TopicId from SSC_Topics where TopicName='" + name + "'", "SSC_Topics").Rows[0][0].ToString();
        }
        public string getLocationNameById(string id)
        {            
            return this.Select_DT("select TopicName from SSC_Topics where TopicId='" + id + "'", "SSC_Topics").Rows[0][0].ToString();
        }
        public string[] getFunctionNameAndFunctionUrlById(string id)
        {
            //Guid TopicId = new Guid(id);
            DataTable dt=Select_DT("select FunctionName,FunctionUrl from SSC_Functions where FunctionId='" + id + "'", "SSC_Functions");
            string[] nameAndUrl=new string[]{"",""};
            if(dt.Rows.Count>0)
            {
                nameAndUrl = new string[]{ dt.Rows[0]["FunctionName"].ToString(), dt.Rows[0]["FunctionUrl"].ToString()};
            }                    
            return nameAndUrl;
        }
        public string getFunctionIdByFunctionName(string name)
        {
            DataTable dt=Select_DT("select FunctionId from SSC_Functions where FunctionName='" + name + "'", "SSC_Functions");
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }
        public string[] getStartEndDateByPartTimeId(string id)
        {
            DataTable dt = Select_DT("select StartDate,EndDate from SSC_PartTimes where PartTimeId='" + id + "'", "SSC_PartTimes");
            string[] SEDate={"",""};
            if (dt.Rows.Count > 0)
            {
                SEDate[0]=dt.Rows[0][0].ToString();
                SEDate[1]=dt.Rows[0][1].ToString();
                return SEDate;
            }
            else
            {
                return SEDate;
            }
        }
        public string getRoleIdByUserId(string id)
        {
            Guid UserId = new Guid(id);
            DataTable dt=Select_DT("select RoleId from SSC_UsersInRoles where UserId='" + UserId + "'", "SSC_UsersInRoles");
            int count = dt.Rows.Count;
            if (count > 0)
            {
                return dt.Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }
        public string getRoleNameByRoleId(string id)
        {
            Guid RoleId = new Guid(id);
            DataTable dt=Select_DT("select RoleName from SSC_Roles where RoleId='" + RoleId + "'", "SSC_UsersInRoles");
            int count=dt.Rows.Count;
            if (count > 0)
            {
                return dt.Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }
        public string getRoleIdByRoleName(string name)
        {
            return this.Select_DT("select RoleId from SSC_Roles where RoleName='" + name + "'", "SSC_Roles").Rows[0][0].ToString();
        }
        public string getAreaNameByAreaId(string id)
        {
            string AreaId = getUserIdByName(id);
            return this.Select_DT("select AreaName from SSC_Areas whereAreaId='" + id + "'", "SSC_Areas").Rows[0][0].ToString();
        }
        public string getAreaIdByAreaName(string name)
        {
            return this.Select_DT("select AreaId from SSC_Areas where AreaName='" + name + "'", "SSC_Areas").Rows[0][0].ToString();
        }
        public string getAreaIdByUserName(string name)
        {
            string userid = getUserIdByName(name);
            return this.Select_DT("select AreaId from SSC_Users where UserId='" + userid + "'", "SSC_Users").Rows[0][0].ToString();
        }
        public string getEmployeeIdByUserId(string id)
        {
            return this.Select_DT("select EmployeeId from SSC_Users where UserId='" + id + "'", "SSC_Users").Rows[0][0].ToString();
        }
        public int getFunctionByUserName(string username,string functionname)
        {
            string roleid = getRoleIdByUserId(getUserIdByName(username));
            string functionid = getFunctionIdByFunctionName(functionname);
            if (functionid != ""&&roleid!="")
            {
                return this.Select_DT("select FunctionId from SSC_RolesFunctions where FunctionId='" + functionid + "' and RoleId='" + roleid + "'", "SSC_RolesFunctions").Rows.Count;
            }
            else
            {
                return 0;
            }
        }
        public string getRoleIdByFunctionId(string id, string rid)
        {
            Guid FunctionId = new Guid(id);
            if (Select_DT("select RoleId from SSC_RolesFunctions where FunctionId='" + FunctionId + "' and RoleId='" + rid + "'", "SSC_RolesFunctions").Rows.Count > 0)
            {
                return this.Select_DT("select RoleId from SSC_RolesFunctions where FunctionId='" + FunctionId + "' and RoleId='" + rid + "'", "SSC_RolesFunctions").Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }
        public string getPartTimeNameByPartTimeId(string id)
        {
            return this.Select_DT("select PartTimeName from SSC_PartTimes where PartTimeId='" + id + "'", "SSC_PartTimes").Rows[0][0].ToString();
        }
        public string getWorkNameByWorkId(string id)
        {
            return this.Select_DT("select WorkName from SSC_Works where WorkId='" + id + "'", "SSC_Works").Rows[0][0].ToString();
        }
        public string getWorkIdByPartTimeId(string id)
        {
            return this.Select_DT("select WorkId from SSC_PartTimes where PartTimeId='" + id + "'", "SSC_PartTimes").Rows[0][0].ToString();
        }
        public string getWorkIdByWorkName(string name)
        {
            if (name != "")
            {
                return this.Select_DT("select WorkId from SSC_Works where WorkName='" + name + "'", "SSC_Works").Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }
        public string getDescriptionByPartTimeId(string id)
        {
            return this.Select_DT("select Description from SSC_PartTimes where PartTimeId='" + id + "'", "SSC_PartTimes").Rows[0][0].ToString();
        }
    }
}

搜索更多相关主题的帖子: 数据库连接 private public 字符串 用户 
2015-03-16 19:50
王钱
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-3-16
收藏
得分:0 
大家帮帮忙啊
2015-03-16 19:51
快速回复:用户代码未处理SqlException 列名AreaId无效
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027972 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved