从表中打印datagrid的最后一行?
问题描述:
我需要以数据网格形式打印表的最后一行.我正在使用sql server和c#.net ..我要打印表的最近插入的行..您能告诉我答案吗..
i need to print the last row of the table in the data grid form .i am using the sql server and c#.net.. i want to print the recently inserted row of the table.. can u tell me the answer..
答
如果您的插入语句在代码中,则可以在插入语句之后使用; SELECT SCOPE_IDENTITY,这将返回您插入的最后一个标识值. />
非常简单,可以从中运行另一个select语句以打印出最后一条记录.
http://msdn.microsoft.com/zh-CN /library/ms190315.aspx [ ^ ]
if your insert statement is in your code, you can use ;SELECT SCOPE_IDENTITY after your insert statement, this will return the last identity value that you inserted..
simple enough to run another select statement from this to print out the last record.
http://msdn.microsoft.com/en-us/library/ms190315.aspx[^]
string sqlInsertActivity = "INSERT INTO activity (CodeID, Subject, ActivityPriorityID, CreatedByEmployeeID, AssignmentTaskStatusID) "
+ "VALUES('82', 'New Document', '2', '" + createdBy + "', '2') "
+ ";SELECT SCOPE_IDENTITY();";
string activityID = SqlHelper.ExecuteScalar(conn, CommandType.Text, sqlInsertActivity).ToString();
以上是我做过的一个快速示例,该示例将一行插入表中并返回刚刚插入的记录的ID
a quick example above of one I did which inserts a row into a table and returns the id of the record just inserted