Learn about vb net database connection with access, we have the largest and most updated vb net database connection with access information on alibabacloud.com
In VB, the method of connecting Access database is mainly shown in the following three kinds of
Use ADO objects. Access the database by writing code
COnnection ObjectODBC Data source
use ado data control
, byref MSG as string) as BooleanDim CMA as sqlcommand = new sqlcommandTryIf CNN. State = connectionstate. Closed thenCNN. open ()End if
CMA. Connection = CNNCMA. commandtext = SQLCMA. commandtype = commandtype. TextCMA. executenonquery ()CNN. Close ()Catch ex as exceptionMSG = ex. MessageReturn falseEnd try
Return trueEnd FunctionEnd Class
When designing this class, I only consider my own usage, because I don't know much about the stored procedure, a
When you use vb to connect to the access database, the following error occurs: Your database is not recognized by the program. The default value of vb is., which is the database type of mdbaccess! At this time, let's take a look a
introduction of Visual Basic.NET database programming and its related knowledge.
First, introduce Ado.net and odbc.net
Ado. NET, improved by Microsoft ActiveX data Objects (ADO), provides platform interoperability and shrinking data access capabilities, and is an important tool used by Visual Basic.NET for database
Add Delete user, this is also related to the database table information Ah! In VB, we can easily call SQL statements with the control of the perfect combination, in vb.net of course there is a more humane way: directly using the control to connect to the databaseSpecific steps:To connect to a data source:Select the table or view or stored procedure that you want, and simply use the statement to display the
= 192.168.24.158; Initial Catalog = CR_Charge_SYS; Persist Security Info = True; User ID = sa; password = 123456 "Dim sqltxt As String =" select * from User_info "'defines the SQL statement Dim sqlconn As New SqlConnection (ConnString)' and defines the connection Dim sqlcmd As New SqlCommand (sqltxt, sqlconn) 'define sqlCommand Dim userReader As SqlDataReader 'define sqldatareader Try sqlconn. open () 'Open the c
add columns before adding rows. In my understanding, it is equivalent to adding fields in the database table before entering data. The effect is as follows:
Sqldatareader
Sqldatareader is a method for obtaining database data. The obtained data is read-only. And it needs to be used with sqlcommand, the most common use method:
Dim connstring as string = _ "Data Source = 192.168.24.158; initial catalog = cr_
access| Create | dynamic | data | database Imports ADOX
Module Module1
Public Function Createaccessdb (ByVal newdbpathname as String) as Integer
Dim I as Integer = 1
Dim Cat as Catalog = New Catalog ()
Try
Cat. Create ("Provider=Microsoft.Jet.OLEDB.4.0;" _
"Data source=" Newdbpathname _
"Jet oledb:engine type=5")
' Console.WriteLine ("Database Created succe
forms designer requiredPrivate components as system. componentmodel. icontainer 'Note: The following procedure is required by the Windows Forms designer'You can use the Windows Form Designer to modify this process.'Do not use the code editor to modify it.Friend withevents button1 as system. Windows. Forms. ButtonFriend withevents savefiledialog1 as system. Windows. Forms. savefiledialogFriend withevents savefiledialog2 as system. Windows. Forms. savefiledialogFriend withevents button2 as system
ADO. NET connection and non-link access to the database, and ado.net connection
// Steps for accessing the database using the connection method
1. Create a
"/>
Selectcommand= "Select * FROM Products"
Datafile= "~/app_data/northwind.mdb"
Onselected= "Accessdatasourcel_selected"
/>
(4) Check the page; When viewing products sold by Northwind, there should be no problem.
(5) The code will now be added to handle the connection problem. Go to the top of the page and go to the following script. The first example is
When I first started to study C # development projects, I had to worry about writing a secure and efficient database connection for a long time. I found that many friends who have just started learning and some who have been friends for a year or two are also a little worried. I will post this code and give myself a reference in the future, it also serves as a learning reference for friends.I have summarize
and enter the following script. The first example is written in C #, and the second example is written in VB. Enter one of them.The following is a script written in VB.Http://www.w3.org/TR/xhtmlll/DTD/xhtmlll.dtd>
(6) Save and run the page. Because our actual connection is still intact, there is no problem yet. Close your browser.(7) Now, move the MDB File of Northwind from \ App_Data to the C: \ Temp fold
This article welcomes the non-commercial use of reprint, but need to indicate from the "Programming Network" and the corresponding URL link.
Let's give you an instance of a connection to an Access database, in this case, Access 2003. First in the E-disk to establish a folder called
discuss how to create a replacement page for the GridView in the case of a failed connection and the details of handling the error event.
Try #4--processing AccessDataSource Connection failed
(1) In the Ch02 folder, create a file named Tio-4-connectionfailure-cs.aspx. In Design view, add a AccessDataSource control to the page that points to Northwind, and the control selects all columns from the tab
Ado. net
Connect to SQL ServerThe SQL Server. NET Framework Data Provider supports connection string formats similar to OLE DB (ADO) connection string formats.Using (sqlconnection connection = new sqlconnection (connectionstring )){Conne
ADO. NET Connect to SQL ServerThe SQL Server. NET Framework Data Provider supports connection string formats similar to OLE DB (ADO) connection string formats.Copy codeThe Code is as follows:Using (SqlConnection connection = new SqlConnection (connectionString )){
ADO. NET
Connect to SQL ServerThe SQL Server. NET Framework Data Provider supports connection string formats similar to OLE DB (ADO) connection string formats.Copy codeThe Code is as follows: using (SqlConnection connection = new SqlConnection (connectionString )){
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.