LEARN CONNECTIVITY TO A DATABASE AND CREATE DATABASE EASILY…..

.1).HOW TO MAKE A CONNECTION TO A DATABASE: GO TO DATA ->> THEN CLICK ADD NEW DATA SOURCE-->>

THEN NEXT THEN CLIK NEW CONNECTION

THEN CHOOSE DATA SOURCE TO MICROSOFT SQL SERVER

THEN GIVE SERVER NAME TO “.”((GIVING DOT SERVER NAME, UR APPLICATION CAN RUN ON ANY SQL SERVER))  THEN EITHER YOU CAN USE WINDOWS AUTHENTICATION OR GIVE A LOGIN NAME “sa” THEN SELECT OR ENTER A DATABASE NAME WHICH U HAVE CREATED BEFORE OR AN EXISTING DATABASE FILE. THEN TEST CONNECTION…IF TEST CONNECTION SUCCEEDED MESSAGE APPEARS IT MEANS THAT CONNECTION IS SET SUCCESSFULLY……

THEN CLIK NEXT THENGIVE THE NAME OF DATASET AND FINISH….

check the table check box..

THEN SELECT THE TEXTBOX OR COMBOBOX WHICH U HV ADDED IN UR FORM.. GO TO::> PROPERTIESDATABINDINGTEXTOTHERDATASOURCES PROJECTDATASOURCES DATASETTABLECOLUMNNAME…… (QUITE LONG :) ) .. THEN YOU WILL SEE SOME DATAADAPTER AND DATASET AT THE BOTTOM OF YOUR FORM…LIKE THIS (ENCIRCLED ONE)

2). HOW TO CREATE A DATABASE IN SQL SERVER.????
OPEN MICROSOFT SQL SERVER FROM START MENU..  THEN OPEN ENTERPRISE MANAGER THEN MICROSOFT SQL SERVERS SQL SERVER GROUPLOCAL DATABASES

THEN IF YOU WANT TO CREATE A NEW DATABASE ..THEN RIGHT CLIK ON THE DATABASES OPTION AND CHOOSE NEW DATABASE . GIVE THE NAME OF DATBASE THEN IF YOU WANT TO CREATE A NEW TABLE--:> THEN RIGHT CLIK ON TABLES OPTION AND SELECT NEW TABLERIGHT CLIK ON THAT TABLE AND OPEN IT IN DESIGN VIEWCREATE COLUMNS U REQUIRED AND THEN SAVE IT AND GIVE THE NAME OF TABLE……TO ENTER SOME DATA IN THE TABLE RIGHT CLIK ON THAT TABLE AND CLIK ON OPEN TABLE THEN RETURN ALL ROWS…

AGAIN COME TO DOTNET…. 3).HOW TO MAKE QUERIES BY WIZARD METHOD IN DOTNET??
RIGHT CLIK ON THE TABLE ADAPTER U HAVE CREATED  THEN SELECT EDIT QUERIES IN DESIGNER  RIGHT CLIK ON TABLEADAPTER AND SELECT ADD QUERY 

 THEN SELECT USE SQL STATEMENTS

THEN CLIK NEXT THEN THIS DIALOG BOX WILL APPEAR

FROM HERE..U CAN SELECT THE TYPE OF QUERY U WANT TO BUILD….

EXA::UPDATE QUERY::>

THEN CLIK ON QUERY BUILDER… THEN RIGHT CLIK ON THE BLANK SPACE AND CLIK ADD TABLE

THEN SELECT THE COLUMS U WANT TO UPDATE…..ALSO U CAN ADD THE WHERE CLAUSE IN IT.,,, THEN WRITE IN THE QUERY “NAME=@NAME AND ADDRESS = @ADDRESS”……… LIKE THIS U CAN CREATE INSERT QUERY DELETE QUERY ETC. FROM WIZARD METHOD… 4). NOW TAKE A FLAG VARIABLE OF TYPE BOOL..SAY “INSERTUPDATEFLAG” THIS FLAG IS TO CHECK ON THE CLICK OF UPDATE BUTTON THAT WHETHER IT IS AN INSERT OR AN UPDATE…(WE ARE GOING TO USE SAME BUTTON FOR INSERT AND UPDATE) SO AFTER DECLARING THE VARIABLE..ON THE CLIK EVENT OF ADD BUTTON OF UR FORM ,,WRITE SOME CODE…

”insertupdateflag = true;”
On the clik event of edit button write…

”insertupdate = false;”

Update query code 
on the click event of update button Write this code if (insertupdate == true) { Int32 rowinserted = it_compTableAdapter.InsertQueryForCompany(textBox1.Text); if (rowinserted > 0) { MessageBox.Show("Records Inserted"); } } else {

Int32 rowupdated = it_compTableAdapter.UpdateQueryForCompany(textBox1.Text, oldvalue); if (rowupdated > 0) { MessageBox.Show("Records Updated"); } }

“EXPLAINATION::” “HERE it_comptableadapter is the name of ur table adapter and the next is ur insertquery which we have build in query builder…. thats all”.

I made this document that’s why it is quite unformatted..so try to understand it……THANKS.. email address ::amit_porwal1@yahoo.co.in Amit porwal………. indore(M.P)

Sign up to vote on this title
UsefulNot useful