获取数据库asp.net c中插入列的id [英] get id for inserted column in database asp.net c#

查看:100
本文介绍了获取数据库asp.net c中插入列的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的项目是将图像上传到服务器

并保存数据库中的路径

问题是如何将id添加到图像名称

这个身份证是身份

我尝试从表数据库添加当前身份

但是我怎么能这样做

任何想法?

字符串x =〜/ myfile / id_image.jpg

此路径将保存在数据库中

所以(id)是DB中的当前行ID

解决方案

如果您使用的是ASP.NET,则可以使用此代码获取最后一个插入ID,Database.GetLastInsertId() [ ^ ]。但是,转向是选择最后一条记录并获取其中的ID列。像这样的东西,



  //   open connection  
var db = Database.Open( databaseName);
// 进行查询,选择TOP 1,DESC从头开始
var selectQuery = SELECT TOP 1 * FROM table_name DESC;
// 获取该列
var column = db.Query(selectQuery);





..现在这个列对象将包含所有值对于该列,所以你可以调用属性来获取此记录的ID。


curr_ident('Table Name')将为您提供最高的标识值

Hi My project is to upload image to server
And save the path on database
The problem is how to add id to image name
And this id is identity
I try to add current id from table database
But how can i do that
Just any idea?
String x = ~/myfile/id_image.jpg
This path will saved in database
So the (id) is current row id in DB

解决方案

If you're using ASP.NET, you can use this code to get the last insert ID, Database.GetLastInsertId()[^]. However, a turn around is to select the last record and get the ID column of that. Something like this,

// open connection
var db = Database.Open("databaseName");
// make the query, to select the TOP 1, DESC to start it from end
var selectQuery = "SELECT TOP 1 * FROM table_name DESC";
// get that column
var column = db.Query(selectQuery);



.. now this column object will contain all of the values for that column, so you can just call the property to get the ID of this record.


curr_ident('Table Name') will give you the highest identity value


这篇关于获取数据库asp.net c中插入列的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆