Welcome to Dream.In.Code
Become a C# Expert!

Join 150,413 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 983 people online right now. Registration is fast and FREE... Join Now!




Oledb

 
Reply to this topicStart new topic

Oledb, How to make it work?

Sharkadder
17 Mar, 2008 - 05:08 AM
Post #1

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 38


My Contributions
Hi , i have recently been trying to use oledb and i am totally stumped.

Basically i hear theres 2 ways you can use oledb, theres the old way which works everytime and the new way which often doesn't update your data.

Using the old way, how can i create a basic oledb application that wll store the value ffrom a text box and then display it into a list box?

So i create a basic table in Access, save it as something daft with 2 colums.

What code would i use to communicate with the table so that once i type a value in the textbox and press submit, it is then sumitted into the table.

I then press File and open, select my file and the values are then all i nthe list box.

so you follow?

So basically i can set up all the form and dialog's etc. I need to type a value into a textbox, on submittion when button1 is pressed, the data gets stored in a database using oledb(the old type commands). Next i press file and save, type in a name in the save dialog, save the file and then finally choose file menu and close form. I then select file menu again and open from my mdi container, i then open the dialog and select the file which appears. I select my saved file which i created and the values from the database need to get put into a listbox.

how is this achieved? thanks, it has really puzzled me, i have search on here and searched and used google and fund no good examples, just a basic 5minute to code example program would do, i can then work off it and create my own, i follow better that way, i dont rip off code, i follow what others have done and do it myself. I work better like that.

thanks

If a basic example you cannot do, then can you at least explain how i do the oledb properly the way i want, just saying use oledbreader and writer isn't exactly helping because i don't know how to use them functions properly.

as i say i searched on how to use these commands and it's all to do with the new way where you edit the db on the form itself, apparently they dont update all the time.

thanks
User is offlineProfile CardPM
+Quote Post

zakary
RE: Oledb
17 Mar, 2008 - 05:44 AM
Post #2

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
Check this link it should help you.

http://msdn2.microsoft.com/en-us/library/s...edb(VS.71).aspx

look at OleDbConnection, OleDbDataAdapter, and OleDbDataReader
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Oledb
17 Mar, 2008 - 06:06 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Here is a tutorial on OleDb Data Objects in C#. Read through that, it will show you at least the basics of using OleDb in C#
User is offlineProfile CardPM
+Quote Post

Sharkadder
RE: Oledb
17 Mar, 2008 - 03:16 PM
Post #4

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 38


My Contributions
hmmm thanks for the examples but that looks complicated.

the examples i was shown were nbot that tricky, for a beginner like me that example means nothing.

What i need is an example i can work off, not aload of code which means nothing. I looked at the examples, the mdsn thing didn't say much, it was just about what each component did, this means tnothing to me as i've not used oledb before, only shown it. The other example was way to complex, i was definatly not shown how to do oledb the old way in that much detail.

Thanks for all the help, it is apprechiated but really i do work better off a working program, not just code snippers to fill in the gaps, any chance somebody can have a working example? all i need is data going in and out of a textbox, that is it.

I can then work off it and use it for things which as strings, filepaths, images etc.

Once something is at least working i am away.

All i need are the write/read commands, that website you showed was more complex that that, it had it own clases for everything, i have not been taught how to program in such ways.

Also i should mention, i use visual studio, as it is easier for me.

i may get confused because alot of this program code is from coding from scratch using linux or other operating system, i find it better to code in visual studio and i use the form commands etc. This may be why i do not understand. It may be drag and drop based but it works for me.

This post has been edited by Sharkadder: 17 Mar, 2008 - 03:22 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Oledb
17 Mar, 2008 - 03:22 PM
Post #5

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Well unfortunately until you start providing the code you've already written in an attempt to solve this we aren't going to supply code, we're not here to do your work for you. The tutorial I linked to was the most basic of tutorials on using the OleDb objects in C#, it really doesn't get more simple and basic than that.
User is offlineProfile CardPM
+Quote Post

Sharkadder
RE: Oledb
17 Mar, 2008 - 03:30 PM
Post #6

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 38


My Contributions
Well i like to think i am an intellient sort of guy, i will try the code tomorrow, i know for a fact i will not be able to do it, i will post where i get up to tomorrow dude, thanks for all the help but i really can not see me understanding the examples.

I will let you all know how i get on and post any code i get stuck on.

cheer's dude. and i don't ask people to do work for me, just i do work better of working example's, the amount of code i have tried and has been totally inaccurate is imense, thats wht i query over all this premade code because half the time i get runtime errors.

thanks for all the help psychocoder, i will let you know what the crack is later.

QUOTE(PsychoCoder @ 17 Mar, 2008 - 04:22 PM) *

Well unfortunately until you start providing the code you've already written in an attempt to solve this we aren't going to supply code, we're not here to do your work for you. The tutorial I linked to was the most basic of tutorials on using the OleDb objects in C#, it really doesn't get more simple and basic than that.


User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Oledb
17 Mar, 2008 - 04:02 PM
Post #7

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
QUOTE

cheer's dude. and i don't ask people to do work for me, just i do work better of working example's



I offered you a tutorial of a working example. The code in that tutorial is a working example, I don't know how it can be more of a working example. When I write it I made it just as basic as I could, and offered a good explanation of every thing I was doing in it, even links to documentation of each control I used.

So, what is your definition of a working example? And how can me posting code here in this thread be any different than the code in the tutorial?
User is offlineProfile CardPM
+Quote Post

davegeek
RE: Oledb
19 Mar, 2008 - 01:35 PM
Post #8

D.I.C Head
Group Icon

Joined: 30 Jan, 2008
Posts: 81



Thanked: 2 times
My Contributions
Let me help you with the examples that I attach here.
Please when distributing them, put the link that some of them were taken/remade from Wrox's "Visual C# for Beginners".

CODE

// DataSetRead allows you to read data from the db, count rows, update rows, and delete rows.
// DataRelationExample (see in Add dir) contains relations between 2 tables + support of reading/writing XML file
// from DataSet.
// ManyRelations contains "primary key" relationships among 4 tables.
// specifies the CompanyName column of row number n - 1 in the Customers DataTable of thisDataSet –
// the DataRow object here is thisDataSet.Tables["Customers"].Rows[n].
thisDataSet.Tables["Customers"].Rows[n]["CompanyName"]


// This program displays SELECT, INSERT, UPDATE, and DELETE queries and counts number of rows in the table

// Specify SQL Server-specific connection string
   SqlConnection thisConnection = new SqlConnection
   (@"Data Source=.\SQLEXPRESS;Integrated Security=SSPI;" + "Initial Catalog=northwind");
   thisConnection.Open();

   SqlDataAdapter thisAdapter = new SqlDataAdapter(
   "SELECT CustomerID from Customers", thisConnection);

   SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
   Console.WriteLine("SQL SELECT Command is:\n{0}\n", thisAdapter.SelectCommand.CommandText);

   SqlCommand updateCommand = thisBuilder.GetUpdateCommand();
   Console.WriteLine("SQL Update Command is:\n{0}\n", updateCommand.CommandText);

   SqlCommand insertCommand = thisBuilder.GetInsertCommand();
   Console.WriteLine("SQL INSERT Command is:\n{0}\n", insertCommand.CommandText);
            
   SqlCommand deleteCommand = thisBuilder.GetDeleteCommand();
   Console.WriteLine("SQL DELETE Command is:\n{0}", deleteCommand.CommandText);

   // to count rows we may use also: DataTable.Rows.Count
   SqlCommand thisCommand = thisConnection.CreateCommand();
   thisCommand.CommandText = "SELECT COUNT(*) FROM CUSTOMERS";
   object countResult = thisCommand.ExecuteScalar();
   Console.WriteLine("Count of Customers = {0}", countResult);

   Console.Read();



Attached File(s)
Attached File  DataGrid.zip ( 91.21k ) Number of downloads: 33
Attached File  DatagridXml.zip ( 15k ) Number of downloads: 30
Attached File  DataSetRead.zip ( 568.48k ) Number of downloads: 33
Attached File  DBApplication.zip ( 797.25k ) Number of downloads: 36
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:45PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month