|
-
Nov 19th, 2006, 07:32 AM
#1
Thread Starter
Fanatic Member
VB2005 Make connection in code and use wizzards????
Hello my friends,
Is it possible to build my connectionstring in code like this:
VB Code:
Imports System.Data.OleDb
Dim oOleDbConnection As OleDbConnection
Dim sConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\myPath\myJet.mdb;" & _
"User ID=Admin;" & _
"Password="
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
And then use the wizards to make a detailform and use the binding navigator, etc...???
-
Nov 19th, 2006, 02:29 PM
#2
Re: VB2005 Make connection in code and use wizzards????
I don't hink you can do that... Using either wizards or code entirely, but not mixing the 2... Maybe I'm wrong though
-
Nov 20th, 2006, 02:11 AM
#3
Thread Starter
Fanatic Member
Re: VB2005 Make connection in code and use wizzards????
Thank you stanav..
You know what the problem is....
I would love to do everything in code...but I am afraid that I will run into problems.
Things like:
-navigating through the records
-Detail forms etc...
And those are things wich you can do very nice with the wizzards...
-
Nov 20th, 2006, 09:51 AM
#4
Fanatic Member
Re: VB2005 Make connection in code and use wizzards????
I do all of my programming for databases in code. I've never used a wizard. I have no problem with updating, inserting, deleting, and navigating. I can show you...?
Warren Ayen
Senior C# Developer
DLS Software Studios ( http://www.dlssoftwarestudios.com/)
I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
Hey! If you like my post, or I solve your issue, please Rate Me!
-
Nov 20th, 2006, 09:58 AM
#5
Thread Starter
Fanatic Member
Re: VB2005 Make connection in code and use wizzards????
 Originally Posted by warrenayen
I do all of my programming for databases in code. I've never used a wizard. I have no problem with updating, inserting, deleting, and navigating. I can show you...?
I would appreceate that very very much....
I hope to hear from you..
Thanks in advance
-
Nov 20th, 2006, 10:05 AM
#6
Fanatic Member
Re: VB2005 Make connection in code and use wizzards????
Well I e-mailed you the functions that I created, but it's really this simple:
VB Code:
Dim sqlConnection As SqlClient.SqlConnection
Dim SqlDataAdapter As SqlClient.DataAdapter
Dim myTable as DataTable
Dim sqlCommand as SqlClient.SqlCommand
sqlConnection = New SqlClient.SqlConnection("connection string")
sqlDataAdapter = New SqlClient.SqlDataAdapter("SQL Query", sqlConnection)
myTable = New DataTable("table name")
sqlDataAdapter.Fill(myTable)
'this will update a record. What you do is make sure you have the current row's ID. All tables should have a Primary Key.
sqlCommand = New SqlClient.SqlCommand("UPDATE tablename SET field = '" & value & "' WHERE IDField = '" & value & "'", sqlConnection) 'change the "value" to the real value, and the tablename, field, and IDField to the fieldnames
sqlConnection.Open
sqlCommand.ExecuteNonQuery
sqlConnection.Close
'this will insert a record. What you do is make sure you have the current row's ID. All tables should have a Primary Key.
sqlCommand = New SqlClient.SqlCommand("INSERT INTO tablename (field = '" & value & "') VALUES (" & value & "," & value & ") WHERE IDField = '" & value & "'", sqlConnection) 'change the "value" to the real value, and the tablename, field, and IDField to the fieldnames
sqlConnection.Open
sqlCommand.ExecuteNonQuery
sqlConnection.Close
'this will update a record. What you do is make sure you have the current row's ID. All tables should have a Primary Key.
sqlCommand = New SqlClient.SqlCommand("DELTE tablename WHERE IDField = '" & value & "'", sqlConnection) 'change the "value" to the real value, and the tablename, field, and IDField to the fieldnames
sqlConnection.Open
sqlCommand.ExecuteNonQuery
sqlConnection.Close
'this will "navigate"
Me.TextBox1.Text = myTable.Rows(index)("Fieldname") 'change index to the selected row, and Fieldname to the name of the column you want to display
That's the code I use
Warren Ayen
Senior C# Developer
DLS Software Studios ( http://www.dlssoftwarestudios.com/)
I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
Hey! If you like my post, or I solve your issue, please Rate Me!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|