求大神帮忙解决,我想了一天没有解决。已经写好了dataset。怎样才能写入ACESS数据库中。 你可以取出里面的记录,插入到数据库中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 大概方法这样,你修改一下: 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(); } 关于使用定时器的问题。 C#应用程序打包问题 关于利用正则表达式删指定内容问题 FileInfo类中OpenText()方法的问题 用过Installer VISE3.6的请进来帮帮忙? 怎在程序集里生成强名称啊!我做的dll都提示错误没有名称啊? 关于datagrid显示图片的问题。 怎样实现打开外部程序后退出,但不影响完不程序的运行? 如何在winform 中的datagrid 中使用 combobox列? 怎样用手柄模拟鼠标 C/S程序中,服务器和客户端之间测速一般怎么实现 怎样获得两个DateTimePicker的天数差?并转换为int型
大概方法这样,你修改一下:
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();
}