Code
private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart(doo));
th.Start();
}
private void doo()
{
SqlConnection conn = new SqlConnection("server=114.80.209.183;database=ichat33;uid=sa;pwd=123456;");
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "select [username],[userpassword] from userinfo ";
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
conn.Close();
DataTable dt = ds.Tables[0];
SqlConnection connN = new SqlConnection("server=114.80.209.183;database=chat;uid=sa;pwd=123456;");
connN.Open();
for (int i = 0; i < dt.Rows.Count; i++)
{
try
{
cmd = new SqlCommand("insert into [user]([name],[passwd]) values('" + dt.Rows[i]["username"].ToString() + "','" + dt.Rows[i]["userpassword"].ToString() + "') ", connN);
cmd.Connection = connN;
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
label1.Text = "成功导入" + (i + 1).ToString() + " " + dt.Rows[i]["username"].ToString();
}
}catch(Exception ex){continue;}
}
conn.Close();
}
private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart(doo));
th.Start();
}
private void doo()
{
SqlConnection conn = new SqlConnection("server=114.80.209.183;database=ichat33;uid=sa;pwd=123456;");
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "select [username],[userpassword] from userinfo ";
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
conn.Close();
DataTable dt = ds.Tables[0];
SqlConnection connN = new SqlConnection("server=114.80.209.183;database=chat;uid=sa;pwd=123456;");
connN.Open();
for (int i = 0; i < dt.Rows.Count; i++)
{
try
{
cmd = new SqlCommand("insert into [user]([name],[passwd]) values('" + dt.Rows[i]["username"].ToString() + "','" + dt.Rows[i]["userpassword"].ToString() + "') ", connN);
cmd.Connection = connN;
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
label1.Text = "成功导入" + (i + 1).ToString() + " " + dt.Rows[i]["username"].ToString();
}
}catch(Exception ex){continue;}
}
conn.Close();
}