小弟我想把原先保存在txt文本中的数据上传到mysql数据库,帮忙看下下边的代码有什么问题,上传不成功:
TXT文本数据格式如下:
fid-fname-fsellprice-fnumber-funitprice-fbarcode
1-硬盒真龙-20-1-20-541001
2-软盒真龙-30-2-15-541002
3-优酸乳-5-2-2.5-541003
4-蒙牛优酸乳-30-6-5-541004
5-面包-1.5-1-1.5-541005
6-可口可乐-4-1-4-541006
7-百事可乐-3-1-3-541007
8-中华火腿-3-2-1.5-541008
9-烤鸡-20-1-20-541009
10-矿泉水-1.5-1-1.5-541010
11-加多宝-4-1-4-541011 private void button2_Click(object sender, EventArgs e)
        {
            DataTable dt = createDataTable();
            Stream mystream;
            //打开文本文件
            OpenFileDialog opfd = new OpenFileDialog();
            opfd.Filter = "(*txt)|*txt";
            opfd.RestoreDirectory = true;
            string path = ""; 
            if (opfd.ShowDialog() == DialogResult.OK)
            {
                if ((mystream = opfd.OpenFile()) != null)
                {
                    mystream.Close();
                }
                FileInfo fi = new FileInfo(opfd.FileName);
                path = opfd.FileName.Substring(0, opfd.FileName.Length);
            }
            StreamReader sr = new StreamReader(path);
            string line = "";
            string[] stemp = null;
            string a = "", b = "", c = "", d = "", ee = "", f = "";
            while ((line = sr.ReadLine()) != null)//每次读取一行
            {
                if (line == "")
                {
                    continue;
                }
                else
                {
                    stemp = line.Split('-');
                    a= stemp[0].ToString();
                    b = stemp[1].ToString();
                    c = stemp[2].ToString();
                    d = stemp[3].ToString();
                    ee = stemp[4].ToString();
                    f = stemp[5].ToString();
                    //创建新行,将每一行的信息存进table中
                    DataRow dr = dt.NewRow();
                    dr["fid"]=a;
                    dr["fname"]=b;
                    dr["fsellprice"]=c;
                    dr["fnumber"] = d;
                    dr["funitprice"]=ee;
                    dr["fbarcode"]=f;
                    dt.Rows.Add(dr);
                }
            }
            
            sr.Close();
      
            string constr = "Server=localhost;User ID=root;Password=wencui2006;Persist Security Info=True;DataBase=ken;charset=utf8";
            MySqlConnection conn = new MySqlConnection(constr);            
            string sql = "";
       
            int fid =Convert.ToInt32(string.Empty);
            string fname = string.Empty;
            double fsellprice =Convert.ToDouble(string.Empty);
            int fnumber =Convert.ToInt32(string.Empty);
            double funitprice =Convert.ToDouble(string.Empty);
            int fbarcode =Convert.ToInt32(string.Empty);
            string s = string.Empty;
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            try
            {                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    fid =Convert.ToInt32(dt.Rows[i]["fid"].ToString());
                    fname = dt.Rows[i]["fname"].ToString();
                    fsellprice =Convert.ToDouble(dt.Rows[i]["fsellprice"].ToString());
                    fnumber =Convert.ToInt32(dt.Rows[i]["fnumber"].ToString());
                    funitprice =Convert.ToDouble(dt.Rows[i]["funitprice"].ToString());
                    fbarcode =Convert.ToInt32(dt.Rows[i]["fbarcode"].ToString() + ' ' + s.ToString());
                    sql = "insert into ftest(fid,fname,fsellprice,fnumber,funitprice,fbarcode) values(" + fid + "," + fname + "," + fsellprice + "," + fnumber + "," + funitprice + "," + fbarcode + ")";
                    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    int count = Convert.ToInt32(cmd.ExecuteNonQuery());
                    if (count == 1)
                    {
                        MessageBox.Show("保存成功", "提示");
                    }
                    else
                    {
                        MessageBox.Show("保存失败","提示");
                    }                }
            }
            catch
            {            }
            finally
            {
                conn.Close();
            }        }
        public DataTable createDataTable()
        {
            DataTable dt = new DataTable("ftest");
            DataColumn fid = new DataColumn();
            fid.DataType = System.Type.GetType("System.Int32");
            fid.ColumnName = "ID";
            dt.Columns.Add(fid);            DataColumn fname = new DataColumn();
            fname.DataType = System.Type.GetType("System.String");
            fname.ColumnName = "Fname";
            dt.Columns.Add(fname);            DataColumn fsellprice = new DataColumn();
            fsellprice.DataType = System.Type.GetType("System.Double");
            fsellprice.ColumnName = "Fsellprice";
            dt.Columns.Add(fsellprice);            DataColumn fnumber = new DataColumn();
            fnumber.DataType = System.Type.GetType("System.Int32");
            fnumber.ColumnName = "Fnumber";
            dt.Columns.Add(fnumber);            DataColumn funitprice = new DataColumn();
            funitprice.DataType = System.Type.GetType("System.Double");
            funitprice.ColumnName = "Funitprice";
            dt.Columns.Add(funitprice);            DataColumn fbarcode = new DataColumn();
            fbarcode.DataType = System.Type.GetType("System.Int32");
            fbarcode.ColumnName = "Fbarcode";
            dt.Columns.Add(fbarcode);            return dt;
        }
    编译提示fid不属于表ftest?,该怎么修改代码?   谢谢