How to Connect database with visual studio 2010?


In this post i will discuss the complete procedure of connectivity of database which has been created in  Microsoft 2003 and with visual studio 2010 
  First of all we create a student or any other table in database i create a table in database 2003 with name of std in table std i take some table attributes such as s-id s-name and s-roll3 these are all the attributes of the table which i create in database and save this table as Microsoft 2003 for creating a extension {.mdb} this extension is very important for the connectivity with out this extension you did not b able to connect database with visual studio because visual studio accept file or database which is save with the name of extension .mdb visual studio did not accept any other extension for connectivity if you save with any other extension it may cause error.
The table snapshot which are given blow show the table which creates in the database with the name of std









 Now save the std table with .mdb extension this snapshot which are given blow show that the std table save with the name of .mdb extension you can also see at the picture in the second row where type of file is written . the database is save as Microsoft office access database (.mdb)


Now we open the visual studio and inset a form from its tool bar  which take three text box and one button in sequence now We entered data in textbox and this data connect to database and this data goes form visual studio database we enter data in the visual studio form or in textboxes an when we press the ok button the data will insert into the database
About this procedure all the snapshot are given blow.


Now we enter connectivity code behind the button which are given blow the code which are given beloww this code in write behind the button.


Private sub button1_click(byval sender as system.object, byval e as system.eventargs)handle button1.click
Dim con as new ADODB.connection()
Dim rs as new ADODB.Recordset()
Con.connection starting ,, “provider ,,Microsoft.jet.OLEDB.4.0;  data source ,, c,,:\user\ghulam haider\desktop\std.mdb;”
Con.open()
Msgbox (“ congrajulation  connection is open”)
Con. Execute(“ inseted into std value(‘ “textbox1.text’ “,  ‘ “textbox2.text’ “,‘ “textbox3.text’ “,) “ )
Msgbox (“ congrajulation data are inserted”)
Con.close()


When you enter the above coding behind the button now you compile the program and when program is compiled a form of visual studio is display you can enter value in the form which are given below you enter your name id and roll number in the given form.



In figure which are given blow you can see and observe that a message is display that connection is open this means that your connectivity is occur and your visual studio is connect with your database  this figure only display your connection.


Now we insert data into the textboxes for example I enter my name haider and id =17 and i enter my roll number 3417 when i insert all these value into the form now i compile the program after compiling you can see that a message is display your data in inserted this mean that your strong connection with database is build and values is inserted to the database

This message shows that data is inserted into database
Now we open database and confirm the process  this database table show that the value which i enter in the above form these all values are inserted into the database i enter my name id and roll number these all value are lie in the database
Database has created which contain std id name and roll number





Post a Comment

Please give us feedback in comments here

 
Top