首页 新闻 会员 周边

列“XXX”不属于表 Table。

0
悬赏园豆:15 [已解决问题] 解决于 2018-05-10 10:53

 1  void JustDisplay()
 2     {
 3         DataTable dt = sql.ExecuteDataset("select * from 核准审批表 where 预约登记号 in (select 预约登记号 from 现场审查表 where id=" + Request.QueryString["id"] + ")");
 4         if (dt.Rows.Count > 0)
 5         {
 6             DataRow ds = dt.Rows[0];
 7             foreach (Control c in divone.Controls)
 8             {
 9                 if (c.GetType().Name == "Literal")
10                 {
11                     Utility.SetZhi(c, ds[c.ID].ToString());
12                 }
13             }
 1 public class Utility 
 2 {
 3     /// <summary>
 4     /// 获取控件的值
 5     /// </summary>
 6     /// <param name="c">控件</param>
 7     /// <returns></returns>
 8     public static string GetZhi(Control c)
 9     {
10         string rt = "";
11         if (c.GetType().Name == "HiddenField") rt = Utility.AntiSqlText(((HiddenField)c).Value);
12         if (c.GetType().Name == "Label") rt = Utility.AntiSqlText(((Label)c).Text);
13         if (c.GetType().Name == "TextBox") rt = Utility.AntiSqlText(((TextBox)c).Text);
14         if (c.GetType().Name == "DropDownList") rt = Utility.AntiSqlText(((DropDownList)c).SelectedValue);
15         if (c.GetType().Name == "RadioButtonList") rt = Utility.AntiSqlText(((RadioButtonList)c).SelectedValue);
16         if (c.GetType().Name == "FCKeditor") rt = ((FredCK.FCKeditorV2.FCKeditor)c).Value.Replace("'", "''");
17         if (c.GetType().Name == "CheckBoxList")
18         {
19             CheckBoxList cl = (CheckBoxList)c;
20             foreach (ListItem i in cl.Items)
21                 if (i.Selected) rt += i.Value + ",";
22             rt = rt.TrimEnd(',');
23         }
24         return rt;
25     }
26     /// <summary>
27     /// 为控件的赋值
28     /// </summary>
29     /// <param name="c">控件</param>
30     /// <param name="zhi"></param>
31     /// <returns></returns>
32     public static string SetZhi(Control c, string zhi)
33     {
34         string rt = "";
35         if (c.GetType().Name == "HiddenField") ((HiddenField)c).Value = zhi;
36         if (c.GetType().Name == "TextBox")
37         {
38             TextBox tb = ((TextBox)c);
39             if (tb.TextMode == TextBoxMode.MultiLine)
40                 tb.Text = zhi.Replace("\r", "").Replace(" ", "&nbsp;");
41             else
42                 tb.Text = zhi;
43         }
44         if (c.GetType().Name == "Label") ((Label)c).Text = zhi;
45         if (c.GetType().Name == "Literal") ((Literal)c).Text = zhi;
46         if (c.GetType().Name == "DropDownList") ((DropDownList)c).SelectedValue = zhi;
47         if (c.GetType().Name == "RadioButtonList") ((RadioButtonList)c).SelectedValue = zhi;
48         if (c.GetType().Name == "FCKeditor") ((FredCK.FCKeditorV2.FCKeditor)c).Value = zhi;
49         if (c.GetType().Name == "CheckBoxList")
50         {
51             CheckBoxList cl = (CheckBoxList)c;
52             foreach (ListItem i in cl.Items)
53             {
54                 i.Selected = false;
55                 if (zhi.Contains(i.Value)) i.Selected = true;
56             }
57         }
58         return rt;
59     }
JenasYang的主页 JenasYang | 初学一级 | 园豆:146
提问于:2018-02-27 16:31
< >
分享
最佳答案
0

未解决,关闭问题。

JenasYang | 初学一级 |园豆:146 | 2018-05-10 10:52
其他回答(4)
0

你这代码666

kingreatwill | 园豆:383 (菜鸟二级) | 2018-02-27 16:58
0

说明zjtyp1这个字段没有在DataTable中,快速跟踪看看

收获园豆:6
gyangjing | 园豆:4 (初学一级) | 2018-02-27 17:32
0

c.ID是你控件的ID值吧(也就是错误提示里面的zjtype1),但是从你的sql语句来看,所有的列估计都是中文命名的,也就是说你的ds(DataRow)中没有用英文字母命名的列zjtype1. 你把ds索引里面的列明改成固定的要的字符串就好了

收获园豆:9
andywangguanxi | 园豆:250 (菜鸟二级) | 2018-02-28 08:55
0

太简单的问题,懒得回答了!

星星点灯6 | 园豆:164 (初学一级) | 2018-03-08 16:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册