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);
}
}
}