你可以取出里面的记录,插入到数据库中

解决方案 »

  1.   


    大概方法这样,你修改一下:
     private void button2_Click(object sender, EventArgs e)
            {
                DataSet ds = new DataSet();
                for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++)
                {
                    string s1 = ds.Tables[0].Rows[i][0].ToString();
                    string s2 = ds.Tables[0].Rows[i][1].ToString();
                    string s3 = ds.Tables[0].Rows[i][2].ToString(); 
                    insertdata(s1,s2,s3);
                }
            }
            public void insertdata(string s1, string s2, string s3)//插入数据库  
            {
                string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=@C:\\Northwind.mdb";
                OleDbConnection con = new OleDbConnection(strConnection);
                con.Open();
                OleDbCommand cmd = new OleDbCommand(string.Format("select Count(*) from newtable where a= '{0}'", s1), con);
                if ((int)cmd.ExecuteScalar() > 0)
                {
                    //listBox1.Items.Add(s1 + " 数据已经存在");
                }
                else
                {
                    string sql = "insert into newtable(a,b,c) values('" + s1 + "','" + s2 + "','" + s3 + "')";
                    cmd.CommandText = sql;
                    cmd.ExecuteNonQuery();
                   // listBox1.Items.Add(s1 + " 成功添加");
                }
                cmd.Dispose();
                con.Close();
            }