Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 . .
Posted

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[^]
C#
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();
 
Share this answer
 
v2
Comments
Raghavendra M 2-Oct-13 2:48am    
Thank u this code is good but i want those data in my form as a table
tanweer 2-Oct-13 2:52am    
add a gridview on your page, and give the datareader to its datasource.
Raghavendra M 2-Oct-13 3:14am    
Yes i did with data grid view but it showing only one record . .
tanweer 2-Oct-13 3:16am    
will you please post your code here what you have done so far?? I suspect you are binding the gridview inside the while loop,
Raghavendra M 2-Oct-13 3:31am    
No i didnt write any code , i just create a form, add a gridview tool for that i add my table . after that , in the insertion code ,aftr inserting i just call that form by show().
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:
C#
//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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900