110,500
社区成员
发帖
与我相关
我的任务
分享
public void InsertTXT(DataSet ds, SqlCommand command)
{
if (ds != null)
{
string sql = @" INSERT INTO [SWBOM.C_PART_MAP_T]
([compal_pn],[cust_pn],[model])
VALUES (@COMPALPN,@CUSTPN,@SKU) ";
DataTable dt = new DataTable();
dt = ds.Tables[0];
int count=dt.Rows.Count;
if (count > 0)
{
command.CommandText = sql;
for (int i = 0; i <= count-1; i++)//减一是把第一行标题去掉
{
string ss = dt.Rows[i][0].ToString();
string ff = dt.Rows[i][1].ToString();
string dd = dt.Rows[i][2].ToString();
command.Parameters.AddWithValue("@COMPALPN", dt.Rows[i][0].ToString());
command.Parameters.AddWithValue("@CUSTPN", dt.Rows[i][1].ToString());
command.Parameters.AddWithValue("@SKU", dt.Rows[i][2].ToString());
command.ExecuteNonQuery();
}
}
}
}
#endregion
#region UnionOperTxT TxT Data
public ExecutionResult UnionOperTxT(DataSet ds) //先Delete表数据,然后Insert
{
ExecutionResult exeRes = new ExecutionResult();
SqlTransaction transaction = null;
try
{
transaction = connection.BeginTransaction();
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.Transaction = transaction;
this.InsertTXT(ds, command);
transaction.Commit();
exeRes.Message = "Insert TXT File Data Success!";
exeRes.State = true;
}
catch (Exception ex)
{
transaction.Rollback();
exeRes.Message = "Insert TXT File Data Fail!"+ex.Message;
exeRes.State = false;
}
return exeRes;
}
#endregion
if (count > 0)
{
command.CommandText = sql;
command.Parameters.Add("@COMPALPN", System.Data.SqlDbType.NVarChar);
command.Parameters.Add("@CUSTPN", System.Data.SqlDbType.NVarChar);
command.Parameters.Add("@SKU", System.Data.SqlDbType.NVarChar);
for (int i = 0; i <= count - 1; i++)//减一是把第一行标题去掉
{
string ss = dt.Rows[i][0].ToString();
string ff = dt.Rows[i][1].ToString();
string dd = dt.Rows[i][2].ToString();
command.Parameters["@COMPALPN"].Value = ss;
command.Parameters["@CUSTPN"].Value = ff;
command.Parameters["SKU"].Value = dd;
command.ExecuteNonQuery();
}
}
for (int i = 0; i <= count-1; i++)//减一是把第一行标题去掉
{
string ss = dt.Rows[i][0].ToString();
string ff = dt.Rows[i][1].ToString();
string dd = dt.Rows[i][2].ToString();
command.Parameters.AddWithValue("@COMPALPN", dt.Rows[i][0].ToString());
command.Parameters.AddWithValue("@CUSTPN", dt.Rows[i][1].ToString());
command.Parameters.AddWithValue("@SKU", dt.Rows[i][2].ToString());
command.ExecuteNonQuery();
}