asp.net读取txt文件内容进oracle数据库出错,搞了1天了,求大神指导。
源码如下:
protected void Button1_Click(object sender, EventArgs e)
{ System.IO.StreamReader my = new System.IO.StreamReader("D:/lyzb/UploadFile/a.TXT", System.Text.Encoding.Default);
string line;
while ((line = my.ReadLine()) != null)
{ Response.Write(line + "</br>");
string[] mm = line.Split(',');
Insert(mm);
} my.Close();
}
private void Insert(string[] mm)
{ string haoma = mm[0];
string qian = mm[1];
string shijian = mm[2];
string qudao = mm[3];
OleDbConnection sqlcnn = new OleDbConnection(ConfigurationManager.ConnectionStrings["yflyzpconn"].ConnectionString);
OracleCommand cmd = new OracleCommand("insert into yf_pay(MBNUMBER,PAYVALUE,PAYTIME,PAYCHANNEL)values(@MBNUMBER,@PAYVALUE,@PAYTIME,@PAYCHANNEL)", sqlcnn);
sqlcnn.Open();
cmd.Parameters.AddWithValue("@MBNUMBER", haoma);
cmd.Parameters.AddWithValue("@PAYVALUE", qian);
cmd.Parameters.AddWithValue("@PAYTIME", shijian);
cmd.Parameters.AddWithValue("@PAYCHANNEL", qudao);
cmd.CommandText = cmd;
sqlcnn.Close();
}
到底哪里有错呀。
------解决方案-------------------- 1:使用存储过程
string mConn = "Data Source=orcl;User Id=dzzj;Password=dzzj;"; //连接数据库
conn = new OracleConnection(mConn);