日期:2014-05-17  浏览次数:21201 次

WinForm SqlDataAdapter 和 DataGridView 的问题
WinForm SqlDataAdapter 中的InsertCommand设置为:

//InsertCommand
            sql = @"insert into tPriceListItem(Name,ResourceName,Price,SubContractor,Admin,OrderId)
                    values(@Name,@ResourceName,@Price,@SubContractor,@Admin,@OrderId);";
            SqlCommand insertCommand = new SqlCommand(sql, conn);
            insertCommand.Parameters.Add("@Name", SqlDbType.VarChar, 500);
            insertCommand.Parameters["@Name"].Value = name;
            insertCommand.Parameters.Add("@ResourceName", SqlDbType.VarChar, 500, "ResourceName");
            insertCommand.Parameters.Add("@Price", SqlDbType.Float, 500, "Price");
            insertCommand.Parameters.Add("@SubContractor", SqlDbType.VarChar, 500, "SubContractor");
            insertCommand.Parameters.Add("@Admin", SqlDbType.VarChar, 500, "Admin");
            insertCommand.Parameters.Add("@OrderId", SqlDbType.BigInt, 500, "OrderId");

            adapterItem.InsertCommand = insertCommand;

表tPriceListItem中有主键自增列Id,我想在adapterItem.Update(dtPriceListItem)之后在dtPriceListItem中的Id列中返回数据库中生成的Id值。怎么个弄法?
winform insert

------解决方案--------------------
select一下max(id)