日期:2014-05-17 浏览次数:20559 次
SqlConnection con = new SqlConnection(connectionString);//连接数据库
con.Open();
SqlTransaction trans = con.BeginTransaction();//事物对象
try
{
SqlCommand com = new SqlCommand();//数据操作对象
com.Connection = con;//指定连接
com.Transaction = trans;//指定事物
string sql = "";
for (int ii = 1; ii < table.Rows.Count; ii++)
{ //对datatable循环
sql = "INSERT INTO [users]([usersID],[usersName],[usersAddress],[usersBirthdate],[usersGender])values ('" + table.Rows[ii]["编号"].ToString() + "','" + table.Rows[ii]["姓名"].ToString() + "','" + table.Rows[ii]["家庭住址"].ToString() + "','" + table.Rows[ii]["生日"].ToString() + "','" + table.Rows[ii]["性别"].ToString() + "')";
//某一行的数据
com.CommandText = sql;
&nbs