哪位大虾帮个忙....大家都来看下...谢谢
2007-04-21 21:07
459 查看
using System;
using System.Data;
using System.Data.OleDb;
public class chibang
{
public static void Main(string[] args)
{
try
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"provider = microsoft.jet.oledb.4.0;data source = ../../../d.mdb";
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = new OleDbCommand("select * from f",conn);
DataSet ds = new DataSet();
da.Fill(ds,"f");
// Console.WriteLine(ds.Tables["f"].Rows[1]["ID"]);
// ds.Tables["f"].Rows[1]["ID"] = "33";
// Console.WriteLine(ds.Tables["f"].Rows[1]["ID"]);
DataColumn[] keys = new DataColumn[2];
keys[0] = ds.Tables["f"].Columns["ID"];
keys[1] = ds.Tables["f"].Columns["di"];
string[] name = {"2222","hack"};
ds.Tables["f"].PrimaryKey = keys;
DataRow dr = ds.Tables["f"].Rows.Find(name);
if(dr == null)
{
DataRow dn = ds.Tables["f"].NewRow();
dn["ID"] = name[0];
dn["di"] = name[1];
ds.Tables["f"].Rows.Add(dn);
}
da.Update(ds,"f");
conn.Close();
//Console.WriteLine(ds.Tables["f"].Rows[1]["ID"]);
Console.ReadLine();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
最后运行完的结果是:当传递具有新行的 DataRow 集合时,更新要求有效的 InsertCommand....
using System.Data;
using System.Data.OleDb;
public class chibang
{
public static void Main(string[] args)
{
try
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"provider = microsoft.jet.oledb.4.0;data source = ../../../d.mdb";
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = new OleDbCommand("select * from f",conn);
DataSet ds = new DataSet();
da.Fill(ds,"f");
// Console.WriteLine(ds.Tables["f"].Rows[1]["ID"]);
// ds.Tables["f"].Rows[1]["ID"] = "33";
// Console.WriteLine(ds.Tables["f"].Rows[1]["ID"]);
DataColumn[] keys = new DataColumn[2];
keys[0] = ds.Tables["f"].Columns["ID"];
keys[1] = ds.Tables["f"].Columns["di"];
string[] name = {"2222","hack"};
ds.Tables["f"].PrimaryKey = keys;
DataRow dr = ds.Tables["f"].Rows.Find(name);
if(dr == null)
{
DataRow dn = ds.Tables["f"].NewRow();
dn["ID"] = name[0];
dn["di"] = name[1];
ds.Tables["f"].Rows.Add(dn);
}
da.Update(ds,"f");
conn.Close();
//Console.WriteLine(ds.Tables["f"].Rows[1]["ID"]);
Console.ReadLine();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
最后运行完的结果是:当传递具有新行的 DataRow 集合时,更新要求有效的 InsertCommand....
相关文章推荐
- 大家热心点帮个忙,谢谢!
- 怎样学习JS语言?谢谢大家帮个忙啊!
- 今天发现成为"推荐博客"了,谢谢大家的支持,我也会更努力的!
- eclipse和myeclipse是如何安装的,有哪位高手指点一下.谢谢
- 上海激动集团有限公司诚聘优秀技术人员(已停止,谢谢大家支持)
- 我该怎么做,请大家帮帮忙,谢谢
- ESRI中国(北京)招聘ArcIMS售后技术工程师(招聘结束,谢谢大家!)
- 谢谢大家的关注
- 大家快来看啊,这就是oracle的真面孔!
- 博客已经搬家,谢谢大家的支持
- 只要你做了,就有分了,谢谢大家帮忙了
- ESRI中国(北京)招聘技术工程师(招聘结束,谢谢大家!)
- 请问大家 如何在夏普vj2c上(wince 3.0)安装flash播放器,谢谢 。能否发一个可用的软件给我,谢谢了,我的邮箱plywoodcn2001@163.com
- 请教大家:如何把.DCU文件反编译回源代码?谢谢。
- 谢谢大家的支持,我现在的BLOG地址是http://syt007.blog.51cto.com/
- SSH集成常见问题。锦囊!谢谢大家把自己的错误以及解决方案贴出来。
- 公司的flash程序员招聘已经结束,谢谢大家的支持
- 哪位大虾给我找一个反编译工具
- 大家来看一个这样的C语言小程序
- 推测题,看哪位大虾能用程序表达推测出答案!