C# 指定了非布尔类型的表达式~新手,望大师帮帮忙

gongxing 2012-12-13 03:05:06
我说下我想实现的程序,我想通过填写textBox1中得数据,转换到数据库中调出相应表的相应字段,然后再将界面中其他textBox13,textBox14,textBox15中得数据一起,转入数据库的另一张表里,我想的方法是下面的程序,但不行,出现了一句什么什么地方(应该是textBox1附近)指定了非布尔类型的表达式,晕,研究半天未果,来这找找大神,看看
SqlConnection sc = new SqlConnection("server=localhost;database=guestbook;uid=gx;pwd=123");
sc.Open();

SqlDataAdapter sda = new SqlDataAdapter("select * from 货物信息 where '" + textBox1.Text
+ "'", sc);
DataSet ds = new DataSet();
sda.Fill(ds);
string a = ds.Tables[0].Rows[1]["货物编号"].ToString();
string b = ds.Tables[0].Rows[1]["发货人"].ToString();
string c = ds.Tables[0].Rows[1]["发货人电话"].ToString();
string d = ds.Tables[0].Rows[1]["发货地址"].ToString();
string f = ds.Tables[0].Rows[1]["收货人"].ToString();
string g = ds.Tables[0].Rows[1]["收货人电话"].ToString();
string h = ds.Tables[0].Rows[1]["收货地址"].ToString();
string i = ds.Tables[0].Rows[1]["货物名称"].ToString();
string j = ds.Tables[0].Rows[1]["货物数量"].ToString();
string k = ds.Tables[0].Rows[1]["货物重量"].ToString();
string l = ds.Tables[0].Rows[1]["货物体积"].ToString();
string m = ds.Tables[0].Rows[1]["货物描述"].ToString();
string n = ds.Tables[0].Rows[1]["运输要求"].ToString();

string sql = "update 集装箱信息 set 集装箱状态 = '使用中' where 集装箱箱号 = '" + textBox13.Text
+ "';insert into 装箱单 values('" + a + "','" + b + "','" + c +"','" + d +"','" + f +"','" + g
+ "','" + h + "','" + i + "','" + j + "','" + k + "','" + l + "','" + m + "','" + n +"','"
+ textBox13.Text + "','" + textBox14.Text + "','" + textBox15.Text + "' ) ";
//MessageBox.Show(sql);
SqlCommand scom = new SqlCommand(sql, sc);
scom.ExecuteNonQuery();
sc.Close();
望大师指点
...全文
351 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dalmeeme 2012-12-13
  • 打赏
  • 举报
回复
说明你的select语句条件不成立,始终为false,这样得到一个空表。
gongxing 2012-12-13
  • 打赏
  • 举报
回复
谢谢了,二楼,已经解决“非布尔类型”类型了,但是他一直显示“在位置1处没有任何行” 我改成:string a = ds.Tables[0].Rows[0]["货物编号"].ToString(); 他又显示“在位置0处没有任何行”,有点无语,谢谢了哈,望解答,感激~~~
hard_learner 2012-12-13
  • 打赏
  • 举报
回复
2楼 正解!
dalmeeme 2012-12-13
  • 打赏
  • 举报
回复
SqlDataAdapter sda = new SqlDataAdapter("select * from 货物信息 where '" + textBox1.Text + "'", sc); 这句where的条件不对,textBox1.Text不是bool型的值。 一般是where 列名='...'。
bdmh 2012-12-13
  • 打赏
  • 举报
回复
哪有 textBox1,是不是某个字段的类型和你传入的值类型不能转换

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧