注册 登录
编程论坛 C# 论坛

不知道哪里错了,就是不行,求解决

ybh24138227 发布于 2015-12-03 12:46, 1769 次点击
string sql = "textBox1.Text";
            string p;
            int a1 = 0, a2 = 1;
            string s = "";
            if (sql.EndsWith("."))
            {
            }

            else
            {
                p = sql.Substring(a1, a2);
                string ssql = "select sz from 移位密码 where yw=p";
                SqlConnection ds = new SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ConnectionString);

                ds.Open();
                SqlCommand bs = new SqlCommand(ssql, ds);
                bs.ExecuteNonQuery();
                int str = Convert.ToInt32(bs);
                ds.Close();
                int k = Convert.ToInt32("textBox3.Text");
                int d = k + str;
                if (d > 25)
                {
                    d = d - 25;
                } string ssql2 = "select yw from 移位密码 where sz=d";
                SqlConnection ds1 = new SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ConnectionString);

                ds.Open();
                SqlCommand bs1 = new SqlCommand(ssql2, ds1);
                bs1.ExecuteNonQuery();
                string str1 = Convert.ToString(bs1);
                ds1.Close();
                a1++;
                a2++;

                s = s + str1;

            }
            textBox2.Text = s;
        


着色的地方显示列名p无效,不懂哪里错了
8 回复
#2
a6464049082015-12-03 16:55
string ssql = "select sz from 移位密码 where yw="+p; //最好用参数化
#3
ybh241382272015-12-04 10:39
回复 2楼 a646404908
string ssql = "select sz from 移位密码 where yw="+p; //最好用参数化 这里什么意思啊,什么叫参数化呀,不懂哎,求解
#4
ybh241382272015-12-04 10:48
回复 2楼 a646404908
试了不行还是原来那个问题啊
#5
ybh241382272015-12-08 14:21
有人没有啊,求大神帮助啊
#6
Maick2015-12-08 15:35
无法改,全是错的
#7
a6464049082015-12-08 17:16
程序代码:
  p = sql.Substring(a1, a2);
                string ssql = "select sz from 移位密码 where yw="+p; //还是+p
                SqlConnection ds = new SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ConnectionString);

                ds.Open();
                SqlCommand bs = new SqlCommand(ssql, ds);
               
                int str = Convert.ToInt32(bs.ExecuteScalar());//这里用ExecuteScalar   然后下面的自己改
                ds.Close();
                int k = Convert.ToInt32("textBox3.Text");
                int d = k + str;
                if (d > 25)
                {
                    d = d - 25;
                } string ssql2 = "select yw from 移位密码 where sz=d";
                SqlConnection ds1 = new SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ConnectionString);

                ds.Open();
                SqlCommand bs1 = new SqlCommand(ssql2, ds1);
                bs1.ExecuteNonQuery();
                string str1 = Convert.ToString(bs1);
                ds1.Close();
                a1++;
                a2++;
#8
JLennon2015-12-09 09:34
select yw from 移位密码 where sz=d//这句在sql server里如何执行?翻一翻sql server语法。
#9
丨渊丨2016-01-25 19:02
其实你完全可以把 select sz from 移位密码 where yw=p 放到 mssqlserver 中 看看能不能查询到数据     

不过我估计 select sz from 移位密码 where yw=‘p’   应该把 p 加上 引号  目测 ym 存放的是 char 或者 nvarchar 类型
1