日期:2014-05-17 浏览次数:20495 次
DataTable dt = new DataTable("T_Nav_1");
dt.Columns.Add(new DataColumn("Nav_1_id", typeof(Int32)));
//dt.Columns.Add(new DataColumn("Nav_1_Name", typeof(System.String)));
dt.Columns.Add(new DataColumn("NavOrder", typeof(Int32)));
for (int i=0; i < ListBox1.Items.Count; i++)
{
dt.Rows.Add(new object[] { ListBox1.Items[i].Value, i });//ListBox1.Items[i].Text,
}
int n = Update(dt);
public int Update(DataTable dt)
{
int res = 0;
dt.PrimaryKey = new DataColumn[] { dt.Columns["Nav_1_id"] };
using (SqlConnection sqlconn = new SqlConnection(DBUtility.PubConstant.ConnectionString))
{
sqlconn.Open();
//事务
SqlTransaction tran = sqlconn.BeginTransaction(IsolationLevel.ReadCommitted);
try
{
foreach (DataRow dr in dt.Rows)
{
//所有行设为修改状态
dr.SetModified();
}
//为Adapter定位目标表
SqlCommand cmd = new SqlCommand("select * from [T_Nav_1] where 1=0", sq