|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Connecting To An Sql Server using .Net Pages
well i've been away from the database designs of asp/.net and mssql, due to working with mostly php/mysql clients.
anyways, i've recently picked up my interest into the .net language and i am now trying to simply connect a .net page to an sql server 2000 database. is there any books or tutorials out there that can help me get over this slight hump. thanks in advance will ![]()
__________________
Apache Expert |
|
#2
|
|||
|
|||
|
There are two way to connect to database in asp.net they are
1) ADO.net 2) ADODB is the old way of connecting to database as same as asp There are many types of connection few are 1) SqlConnection (this is only for SQL Server this will be faster because it is connection SQL Server directly) 2) OleDbConnection (this is for all database oracle,access,sql server and etc.) 3) OdbcConnection Here I am using only SqlConnection In Ado.net there are two type of retrieving the details from database 1) Using DataSet 2) Using Data Reader 1) Dataset it is the advanced way of using database. In this u can maintain the relation and it is disconnected environment that means once you retrieved the data's form the database and fill in the dataset you can close the connection after you closed the connection also you can work with is data's. After changes are made you can open the connection and update the changes Imports System.Data.SqlClient Public Class Form1 Inherits System.Windows.Forms.Form Dim SqlConn As SqlConnection Dim SqlDA As SqlDataAdapter Dim SQLDS As DataSet Dim DRow As DataRow Private Sub Form1_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load SqlConn = new SqlConnection("connection String") SqlDA = new SqlDataAdapter("SqlQuery",SqlConn) SqlDA.Fill(DS,"Any Name for the Reference") For Each DRow In ds.Tables ("Customer").Rows ComboBox1.Items.Add (DRow("Customer_Name")) Next End Sub End Class 2) Data Reader it will give the recordset as readonly and forward only. Imports System.Data.SqlClient Public Class Form1 Inherits System.Windows.Forms.Form Dim SqlConn As SqlConnection Dim SqlComm As SqlCommand Dim SqlDR As SqlDataReader Private Sub Form1_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load SqlConn = new SqlConnection("connection String") SqlConn.open() SqlComm = new SqlCommand("SqlQuery",SqlConn) SqlDR = Sqlcomm.ExecuteReader While (SqlDR.Read) ComboBox1.Items.Add(SqlDR("Col_Name")) End While End Sub End Class |
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > Connecting To An Sql Server using .Net Pages |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|