C# System.Web.HttpException:“在选定的数据源上未找到名为“sjb”的字段或属性。”

        public  static DataTable SelectSQL(string a)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(a, connection))
                {
                    using (SqlDataAdapter da = new SqlDataAdapter(command))
                    {
                        DataSet ds = new DataSet();
                        try
                        {
                            da.Fill(ds, "ds");
                            command.Parameters.Clear();
                        }
                        catch (System.Data.SqlClient.SqlException ex)
                        {
                            throw new Exception(ex.Message);
                        }
                        connection.Close();
                        return ds.Tables[0];
                    }
                }
            }
        }

        public string SelectQuan()
        {
            string name = System.Web.HttpContext.Current.Request["TextBox1"].ToString();
            string str = "select * from B join C on B.name = C.姓名";
            if (name == "")
            {
                System.Web.HttpContext.Current.Response.Write("请输入名字");
            }
            else if (name != "" && name.IndexOf(',') == -1)
            {
                str = "select * from B join C on B.name = C.姓名 where B.name = '" + name + "'";
                SelectSQL("select * from B join C on B.name = C.姓名");
                string[] arr = SelectSQL("select * from B join C on B.name = C.姓名").AsEnumerable().Select(d => d.Field<string>("name")).ToArray();
                int w = 0;
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i] == name)
                    {
                        w++;
                    }
                }
                if (w != 1)
                {
                    System.Web.HttpContext.Current.Response.Write("你输入的名字不存在");
                }
            }
            else if (name.IndexOf(',') > -1)
            {
                str = "select * from B join C on B.name = C.姓名 where name =";
                SelectSQL("select name from B");
                string[] arr = SelectSQL("select name from B").AsEnumerable().Select(d => d.Field<string>("name")).ToArray();
                string[] array = name.Split(',');//
                int count = array.Length;
                int count1 = 0;
                for (int k = 0; k < array.Length; k++)
                {
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if (arr[j] == array[k])
                        {
                            count1 += 1; //计数器
                        }
                    }
                }
                if (count1 != count)
                {
                    System.Web.HttpContext.Current.Response.Write("你输入的名字中有不存在的人名");
                }
                for (int i = 0; i < array.Length; i++)
                {
                    str += "'" + array[i] + "'";
                    if (i != array.Length - 1)
                    {
                        str += "or B.name =";
                    }
                }
            }
            return str;
        }

 这种情况是怎么回事,GridView控件都绑定了,是哪出问题了,求大神指点

  • 14
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值