插入数据库, 记录的顺序怎么总是不对啊?
下面这段程序,是读取文件中的每一行,然后顺次插入到数据库中,有这么几个问题:
1.插入后记录的顺序总是不对,虽然我肯定是顺次读取并插入的。
2.Transaction到底要不要commit啊,为什么我没有commit,对结果没什么影响?
Computer mycomputer = new Computer();
using (StreamReader myReader = mycomputer.FileSystem.OpenTextFileReader(data_file.FullName, Encoding.Default))
{
using (OracleConnection myOracleConnection = new OracleConnection(mySetting.ConnectionString))
{
myOracleConnection.Open();
while (myReader.Peek() != -1)
{
info = myReader.ReadLine();
unitname = info.Substring(25, 8);
#region insert
//OracleTransaction insert_transaction = null;
//insert_transaction = myOracleConnection.BeginTransaction(IsolationLevel.Serializable);
//insert_transaction = myOracleConnection.BeginTransaction();
try
{
string @insert_string = "insert into tbdl02 (ser,datatype,result,data,cjrq,cjsj) "
+ "values (:ser, ' ',0,:data,:cjrq,:cjsj) ";
OracleCommand insert = new OracleCommand(insert_string, myOracleConnection);
insert.Parameters.Add( "ser ", OracleType.Char).Value = DateTime.Now.ToString( "yyyyMMddHHmmssffff ") + ". " + count.ToString() + (rnd).Next(5000).ToString();