从MSAccess数据库中重新获取数据 [英] Retriving Data from MSAccess Database
本文介绍了从MSAccess数据库中重新获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MSAccess数据库中插入了一些数据。 。 ,现在我想以表格形式显示它们,为此,我使用的是什么项目,是代码片段。 。
解决方案
就像在数据库中插入记录一样简单
详细信息在此链接上给出 http://stackoverflow.com/questions/15148588/proper-way-of-从访问数据库中获取数据 [ ^ ]
cmd.CommandType = CommandType.StoredProcedure;
OleDbConnection connection = new OleDbConnection( @ Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\ Users \ redgabanan \Desktop\Gabanan_Red_dbaseCon\Red_Database.accdb);
connection.Open();
OleDbDataReader reader = null ;
OleDbCommand command = new OleDbCommand( SELECT *来自用户WHERE LastName =' + textBox8.Text + ',连接) ;
reader = command.ExecuteReader();
DataGrid1.DataSource = reader;
DataGrid1.DataBind();
你好再次Raghavendra :)
正如我之前对你的问题的回答所述 - 你应该认真检查这些链接 - 在那里你会找到一步一步的指导。
如果不清楚 - 请查看下面的内容:
// Csome与MS Access DB的连接类型(无论是oleDb还是PDBC)
// 在这种情况下,我们可以使用DBC
// 取决于您可能需要使用不同提供商的MS Access版本
// Microsoft.ACE.OLEDB.12.0,Microsoft.ACE.OLEDB.8.0等。
string ConnectionString = @ Provider = Microsoft.ACE.OLEDB.12。 0;数据源= C:\ Data.accdb;
OleDbConnection oConnect = new OleDbConnection(ConnectionString);
oConnect.Open();
// 现在当连接打开时,我们可以用它来做任务:
string SQL_Command = SELECT [SomeColumnName] FROM [SomeTableName] 跨度>;
OleDbCommand oCommand = new OleDbCommand(SQL_Command,oConnect);
OleDbDataReader dReader = oCommand.ExecuteReader();
// 现在dReader有吃掉的东西,所以我们可以遍历它:
列表< dynamic> myData = new 列表< dynamic>();
while (dReader.Read())
{
myData.Add(dReader.GetValue( 0 跨度>));
}
oConnect.Close();
// 现在你的变量myData将从MS Access DB中获取所有数据,你可以用...显示在某处或做LINQ的东西......或其他东西。< / dynamic>< / dynamic>
干杯!
Modestas。
PS:请阅读我之前给你的链接
I have inserted some data in MSAccess database . . , now I want to display them in form in tabular form , for that ,what item shoud i use and wht is the code snippet . .
解决方案
hi, it is as simple as you insert records in database
detail are given on this link http://stackoverflow.com/questions/15148588/proper-way-of-getting-a-data-from-an-access-database[^]
cmd.CommandType = CommandType.StoredProcedure; OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\redgabanan\Desktop\Gabanan_Red_dbaseCon\Red_Database.accdb"); connection.Open(); OleDbDataReader reader = null; OleDbCommand command = new OleDbCommand("SELECT * from Users WHERE LastName='"+textBox8.Text+"'", connection); reader = command.ExecuteReader(); DataGrid1.DataSource=reader; DataGrid1.DataBind();
Hello again Raghavendra :)
As stated in my previous answer to your question - you should seriously check these links - there you will find step by step guidance.
If that is not clear - check bellow:
//Csome sort of connection to MS Access DB (whether it is oleDb or PDBC) //in this case lets use DBC //depending on your MS Access version you might need to use different providers //Microsoft.ACE.OLEDB.12.0, Microsoft.ACE.OLEDB.8.0 and etc. string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Data.accdb"; OleDbConnection oConnect = new OleDbConnection(ConnectionString); oConnect.Open(); //now when connection is open we can do stuff with it: string SQL_Command = "SELECT [SomeColumnName] FROM [SomeTableName]"; OleDbCommand oCommand = new OleDbCommand(SQL_Command, oConnect); OleDbDataReader dReader = oCommand.ExecuteReader(); //now dReader has the stuff "eaten" so we can loop through it: List<dynamic> myData = new List<dynamic>(); while (dReader.Read()) { myData.Add(dReader.GetValue(0)); } oConnect.Close(); //now your variable myData will have all data taken from the MS Access DB and you can do something with... display somewhere or do LINQ stuff... or something else.</dynamic></dynamic>
Cheers!
Modestas.
P.S.: please read the links that I gave you before.
这篇关于从MSAccess数据库中重新获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文