Showing posts with label Microsoft SQL Server. Show all posts
Showing posts with label Microsoft SQL Server. Show all posts

Monday, May 27, 2013

यह Microsoft द्वारा develop किया गया एक Dababase server software है जो की RDBMS को support करता है। यह SQL language का use कर data accessing provide करता है। Microsoft की सभी programming language इसे support कर database के लिए use कर सकती हैं। यह ADO.Net का एक महत्वपूर्ण हिस्सा है। ADO.Net data provider इसके लिए अलग से सभी data accessing facilities provide करती है। इसे use करने के लिए सबसे पहले SQLClient namespace को import करते हैं जिसके लिए imports System.Data.SqlClient statement का use किया जाता है। इसमें निम्न classes होती हैं। SQLDB के लिय SQLConnection object का use किया जाता है। 

 



  • Connection: SQLDB मे SQLConnection class का use किया जाता है। यह SQL Server से डाटा access करने के लिए use की जाता है। इसके लिए Design mode मे Sqlconnection toolitem का use करते हैं जो की Toolbox में Data category मे उपलब्ध रहता है। इसे form पर place कर इसे use किया सकता है। coding के द्वारा इसे इस use करने के लिए सबसे पहले SQLConnection class का object बनाते है और उसमें ConnectionString को define करते हैं। इसके बाद connection को open कर use किया जा सकता है। इसमें निम्न प्रकार की connection string का use किया जा सकता है।


Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;


Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=True;


 


Imports System.Data.SqlClient

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim constring As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\SQL Server 2000 Sample Databases\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"

Dim con As SqlConnection = New SqlConnection(constring)

Try

con.Open()

MsgBox("Connected Sucessfully")

con.Close()

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

End Class


 



  • Command: SQL connection के लिए SQLCommand class के object का use किया जाता है। इसे use करने के लिए इसका object declare कर लेते हैं और उसकी सभी important properties को define कर methods को call कर लेते हैं।


Imports System.Data.SqlClient

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim constring As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\SQL Server 2000 Sample Databases\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"

Dim con As SqlConnection = New SqlConnection(constring)

Dim cmd As SqlCommand = New SqlCommand

cmd.Connection = con

cmd.CommandText = "Select * from Products"

Try

con.Open()

Dim dr As SqlDataReader = cmd.ExecuteReader

dr.Read()

MsgBox(dr.Item(0))

con.Close()

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

End Class


 



  • DataAdapter और DataSet:  इसमें DataAdapter SQLDataadpter और dataset normal dataset का object होता है।


Dim con_str As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\SQL Server 2000 Sample Databases\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"

Dim con As New SqlConnection(con_str)

Dim ada As SqlDataAdapter

Dim ds As New DataSet

Try

con.Open()

ada = New SqlDataAdapter("Select * from Products", con)

ada.Fill(ds)

con.Close()

Dim i As Integer

For i = 0 To ds.Tables(0).Rows.Count - 1

MsgBox(ds.Tables(0).Rows(i).Item(1))

Next

Catch ex As Exception

MsgBox(ex.Message)

End Try

Contact us

Name

Email *

Message *