| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 996 人关注过本帖
标题:c#varchar类型转换为int
只看楼主 加入收藏
Donnie
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-10-19
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:4 
c#varchar类型转换为int
我从数据库里读出来的数据都是,varchar类型,转换成int,老是出错,不知道怎么办,新手.小弟才上,实在没有分给,对不住了,谢谢,助人为乐吗!!!代码如下:

    struct Employee
    {
        public string PictureFile;
        public string  Page;
      
    }



    class DownFile
    {
        MyMeans MyMean = new MyMeans();
        MyModule MyModule = new MyModule();
        string My_con = MyMeans.M_str_sqlcon;

      

        public void treeView1_AfterSelect()
        {
            int CurRec = 1;  //初始化记录计数器
            //int rec_count=0; //计算总记录数
           //public PictureFiles;

          string i = DateTime.Now.Date.ToString();
         

       try
       {
           SqlConnection conn = new SqlConnection(My_con);
           string sql = "select COUNT(*)  from PICTURE";
           //string sql = "select UNITID,PICTUREFILE,PICFORMAT from PICTURE  order by UNITID";
           SqlDataReader AD = MyMean.getcom(sql);
           SqlCommand cmd = new SqlCommand(sql, conn);
      
            AD.Read();
            int   a  = Convert.ToInt32(AD[0].ToString ());
         
         
           conn.Open();
        
           SqlDataReader dr = null;

         

           sql = "select   PAGEID,PICTUREFILE from PICTURE  order by PAGEID";
         

         // cmd = new SqlCommand(sql, conn);


           dr = cmd.ExecuteReader();
           Employee[] tuser = new Employee[a];
           while (dr.HasRows)
           {
               dr.Read();
               int DQ_id = (int)user_info.getvalue(0);
               tuser[CurRec].PictureFile = (int)dr.GetInt32(0);
               //tuser[CurRec].PictureFile = Convert.ToInt32(dr[0].ToString());
               tuser[CurRec].Page = Convert.ToInt32(dr[1].ToString());
               CurRec += 1;
               

              // byte[] bytes = (byte[])dr[" PAGEID"];


               FileStream fs = new FileStream(@"c:\Picture\" + dr["PICTUREFILE"] , FileMode.Create, FileAccess.Write);
                   ///FileStream fs = new FileStream(@"mkdir temphack" + dr["UNITID"], FileMode.Create, FileAccess.Write);

                  //fs.Write(bytes, 0, bytes.Length);
                   fs.Flush();
                   fs.Close();
               

               dr.Close();
               conn.Close();

           }

     }
               
            catch (Exception ex)
            {
                MessageBox.Show("下载文件发生异常 : " + ex.Message);
            }
           }

         
        }
搜索更多相关主题的帖子: int 类型 varchar 
2009-09-22 23:20
ljc_zy
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:56
专家分:131
注 册:2009-7-14
收藏
得分:7 
是注释的代码有问题吗?

恋恋花事 www.
2009-09-23 07:06
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:7 
哪一句有问题啊

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-09-23 08:37
Donnie
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-10-19
收藏
得分:0 
tuser[CurRec].PictureFile = (int)dr.GetInt32(0);
tuser[CurRec].Page = Convert.ToInt32(dr[1].ToString());

这两句
2009-09-23 22:59
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:0 
tuser[CurRec]这种方式比较不规范
用List<Employee> tuser;定义
然后可以用tuser.Add()方法添加成员

tuser[CurRec].PictureFile = (int)dr.GetInt32(0);
没看懂什么意思,编译提示什么错误?

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-09-23 23:40
快速回复:c#varchar类型转换为int
数据加载中...
 
   



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

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