Oledb

How to make it work?

Page 1 of 1

7 Replies - 7020 Views - Last Post: 19 March 2008 - 02:35 PM Rate Topic: -----

#1 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Oledb

Post icon  Posted 17 March 2008 - 06:08 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Oledb

#2 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: Oledb

Posted 17 March 2008 - 06:44 AM

Check this link it should help you.

http://msdn2.microso...edb(VS.71).aspx

look at OleDbConnection, OleDbDataAdapter, and OleDbDataReader
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Oledb

Posted 17 March 2008 - 07:06 AM

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#
Was This Post Helpful? 0
  • +
  • -

#4 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Re: Oledb

Posted 17 March 2008 - 04:16 PM

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 March 2008 - 04:22 PM

Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Oledb

Posted 17 March 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.
Was This Post Helpful? 0
  • +
  • -

#6 Sharkadder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 17-March 08

Re: Oledb

Posted 17 March 2008 - 04:30 PM

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.

View PostPsychoCoder, on 17 Mar, 2008 - 04:22 PM, said:

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.

Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Oledb

Posted 17 March 2008 - 05:02 PM

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?
Was This Post Helpful? 0
  • +
  • -

#8 davegeek  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 81
  • Joined: 30-January 08

Re: Oledb

Posted 19 March 2008 - 02:35 PM

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".

// 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)


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1