C#问题访问数据库,归档排序。 [英] C# problem Access database , filed sorting .

查看:65
本文介绍了C#问题访问数据库,归档排序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在访问数据库中,他id字段我想再次对它进行排序,例如如果id提交的是1,22,30。

i想要它1,2,3

这个代码。

in access database, he id field i want to sort it again, such as if the id filed was 1,22,30 .
i want make it 1,2,3
this the code .

OleDbConnection h5 = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\IJC Database.accdb");
            OleDbConnection h6 = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\users\\IJC Database.accdb");
            OleDbCommand cmd5;
            OleDbCommand cmd6;
            h5.Open();
            cmd5 = new OleDbCommand("select count(ID) from ijc"+";",h5);
            int countID = (int)cmd5.ExecuteScalar();
            h5.Close();
            h6.Open();
            for (int i = 1; i <= countID; i++)
            {
                cmd6 = new OleDbCommand("update ijc set ID='"+i+"';",h6);
                cmd6.ExecuteNonQuery();
            
            }
            h6.Close();



但是如何移动到下一个id ...


but how can i move to the next id...

推荐答案

您可能需要澄清您真正想要做的事情。如果您使用ID作为排序列并且正在尝试调整ID,那么您实际上是反对ID列的用途。



看看这样,如果你在数据库中有另一个表(称之为Table2),用ID引用(称之为Table1),你更新表1中的ID而不是Table2中的ID,那么你就破坏了两个表。



如果您只想使用ID对结果进行排序,您的选择查询应如下所示:



You may have to clarify what you are really trying to do. If you are using the ID as a sorting column and are trying to adjust the ID's, then you are really going against what the ID column is used for.

Look at it this way, if you have another table in the database (call it Table2) that references (call it Table1) by ID, and you update the ID's in Table 1 but not the ones in Table2, then you've broken every relationship in the two tables.

If you only want to use the ID to sort the results, your select query should look something like this:

SELECT * FROM ijc ORDER BY ID





哪个会按ID订购。你应该在数据库中做的最后一件事是重新订购ID,id只是一个数字,不要过分强调订单。



Which will order by ID. The last thing you should ever do in a database is re-order ID's, id's are just a number, don't put too much emphasis on the order.


你想要重新订购 - 使用例如获得免费的ID值从数据库中删除一些行?那是一项无用的任务! ID是自动生成的值,其唯一目的是标识行。填补值之间的差距不会改变数据库的性能。
Do you want to "re-use" ID values which got free by e.g. deleting some rows from the database? That's a useless task! The ID is an automatically generated value, its only purpose is to identify a row. Filling up the gaps between the values won't alter peformance of your database.


我相信它会在它上面工作。



string query =select * from+TableName+Order by+ID;
I am sure it will be working on it.

string query = "select * from " + "TableName" + " Order by" + " ID";


这篇关于C#问题访问数据库,归档排序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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