我写了一个存储过程,其中最后一个参数为output。
我新建一个DATASET,然后将存储过程拖进DATASET,自动生成TableAdapter:QueriesTableAdapter
但是QueriesTableAdapter不但没有CONNECTION属性,而且也得不到OUTPUT的值using (QueriesTableAdapter da = new QueriesTableAdapter())
{
Guid m_eventGuid=Guid.Empty;
int m_end; m_end = da.esVendition_Log_sp_GetEventGuid(fldEventDate, fldOperator, fldEventType, ref m_eventGuid);
return m_eventGuid;
}Error 1 The best overloaded method match for 'Easysoft.Vendition.Entity.LogEventDSTableAdapters.QueriesTableAdapter.esVendition_Log_sp_GetEventGuid(System.DateTime?, System.Guid?, int?, ref System.Guid?)' has some invalid arguments E:\ESUAP3\Easysoft.Vendition\LogManager.cs 112 29 Easysoft.VenditionError 2 Argument '4': cannot convert from 'ref System.Guid' to 'ref System.Guid?' E:\ESUAP3\Easysoft.Vendition\LogManager.cs 112 109 Easysoft.Vendition
我新建一个DATASET,然后将存储过程拖进DATASET,自动生成TableAdapter:QueriesTableAdapter
但是QueriesTableAdapter不但没有CONNECTION属性,而且也得不到OUTPUT的值using (QueriesTableAdapter da = new QueriesTableAdapter())
{
Guid m_eventGuid=Guid.Empty;
int m_end; m_end = da.esVendition_Log_sp_GetEventGuid(fldEventDate, fldOperator, fldEventType, ref m_eventGuid);
return m_eventGuid;
}Error 1 The best overloaded method match for 'Easysoft.Vendition.Entity.LogEventDSTableAdapters.QueriesTableAdapter.esVendition_Log_sp_GetEventGuid(System.DateTime?, System.Guid?, int?, ref System.Guid?)' has some invalid arguments E:\ESUAP3\Easysoft.Vendition\LogManager.cs 112 29 Easysoft.VenditionError 2 Argument '4': cannot convert from 'ref System.Guid' to 'ref System.Guid?' E:\ESUAP3\Easysoft.Vendition\LogManager.cs 112 109 Easysoft.Vendition
个人以为DataSet适合用作批量数据,比如读取一个表什么的
output参数适合执行插入/更新等操作
使用存储过程又用DataSet又用output参数 难道返回一个游标做数据集?
标记 学习一下
DataColumn dc = dt.Columns["id"];//这一列对应的数据库中的表字段是自增列,
在内存DataTable中进行批输入更新时不能马上得到新输入的上一条记录的主键,
所以建立临时唯一主键如下:
dc.AutoIncrement = true;//设置该列为自增长,
dc.AutoIncrementSeed = -1;//新增列的初始值。
dc.AutoIncrementStep = -1;//列的值自动递增的数值。默认为 1。
这样你添加第一条新增数据的时候临时主键为-1,
第二条为-2,
...
在使用DataAdapter.Update(dt);进行更新的时候,
如果数据源是Sql Server那使用存储过程输出参数把自增主键输出会自动更新新增的DataRow,
比如上面的-1,-2,-3等自动会更新成实际数据库中的自增主键值。
这种方式具体可以看我的一片文章,
http://blog.csdn.net/zhzuo/archive/2004/08/06/67037.aspx
如果是Access或其他数据库就有点麻烦,回填实现如下:
注册DataAdapter.RowUpdated事件。
da.RowUpdated += new OleDbRowUpdatedEventHandler(da_RowUpdated);
事件处理程序,
private static void da_RowUpdated(object sender, OleDbRowUpdatedEventArgs e)
{
if(e.Status == UpdateStatus.Continue && e.StatementType = StatementType.Insert)
{
OleDbConnection conn = new OleDbConnection("连接字符串");
OleDbCommand comm = new OleDbCommand("SELECT @@IDENTITY",conn);
conn.Open();
e.Row["id"] = (int)comm.ExecuteScalar();//得到最新递增值更新到内存DataTable中刚更新的DataRow.
e.Row.AcceptChanges();
conn.Close();
}
}
//处理程序中的每次生成conn,和comm没有必要,你可以只初始化一次,这里这么写只是为了说明过程,而且也没有必要多次打开或关闭连接。
http://blog.csdn.net/zhzuo/archive/2004/08/06/67037.aspx