yaniv Posted December 23, 2002 Posted December 23, 2002 I know this question asked before, but i cant make the connection to the database, can't even find the right statment to make in the Dim stament. can any body give sample code for it? should i put the oledbconnection controler on the bord? how do i make the connection move one record? i just can't make it!! Quote
dejota6 Posted December 26, 2002 Posted December 26, 2002 yaniv, if you can wait about an hour or so when I get to my lunch break, I will be more than happy to whip you up a quick little tutorial so to speak on how to get the database connection you want. I will be back then, so if someone has already responded, I will not. And although I can have you up and running with a few easy steps, it might not be the most efficient. So just a little forewarning. Quote
dejota6 Posted December 26, 2002 Posted December 26, 2002 As promised, I am back to give you a short tutorial the best I know how. First, you will need to add a reference to your project. To do this, go to the Project -> Add Reference. Go to the "COM" tab and scroll down to find the Microsoft ActiveX Data Objects 2.7 Library. Highlight it and click Select on the Right. Click OK to add the reference and if asked, click Yes to add the wrapper (if not asked, don't worry about it). here is what it will look like (roughly) http://www.tonka6969.homestead.com/files/AddReference.JPG Then in your code use this. Dim cnADOConnection As New ADODB.Connection() To open your connection, use the following, I am assuming you are using access, so I will include that. m_cnADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = "C:\Filename.mdb") I set my recordset variables as global, but it is up to you. where ever you want to put the code, you can. Dim rstRecordset as New ADODB.Recordset() When opening your recordset, use the following format: rstRecordset.Open("TableName", m_cnADOConnection, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic) Now, of course, the permissions you set will vary according to what you want to do with it. These permissions give you the most freedom. Finally, to move around in the records, and such. rstRecordset.MoveFirst rstRecordset.MovePrevious rstRecordset.MoveNext rstRecordset.MoveLast Also, by typing rstRecordset and then a period, you can search through some of the other methods and properties of the recordset that you can play with. Hopefully, that will give you some help. if you need any more help, just let me know and I will try to the best of my ability. Like I said before, this might not be the best way to do it, but it works. Good Luck. Quote
yaniv Posted December 27, 2002 Author Posted December 27, 2002 Thanks a lot for the comprehensive help!! Quote
*Experts* Nerseus Posted December 30, 2002 *Experts* Posted December 30, 2002 Do you really want to use ADODB (COM) and not the new ADO.NET provider? ADO.NET is soooo much nicer... The MSDN docs are filled with sample code. If you need me to post some, let me know. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
yaniv Posted December 30, 2002 Author Posted December 30, 2002 i tryed to use ADO, but i have problem: I copyed samle of thinker from this forum to run connection to access table and i"m getting the same error all the time: "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll" the code is: Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click Dim name As String Dim sql As String Dim cn As New OleDb.OleDbConnection() Dim dr As OleDb.OleDbDataReader cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Documents and Settings\éðéá\My Documents\àìáåí úîåðåú.mdb" cn.Open() sql = "select * from mainform" Dim cmd As New OleDb.OleDbCommand() cmd.Connection = cn cmd.CommandText = sql dr = cmd.ExecuteReader() While dr.Read() Debug.Write(dr("picture")) End While dr.Close() cn.Close() End Sub and i get the error when he get's to the executereader line. what should i do? will be very thankfull if you can send working sample. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.