|
-
February 4th, 2006, 05:23 AM
#1
connect to sql server
what is wrong in my code? i cant see the records of the dataBase
Code:
If (Not Page.IsPostBack) Then
Dim con As SqlConnection = New SqlConnection ("Server=localhost;Database = Northwind;Integrated Security = SSPI;")
Dim cmd As SqlCommand = New SqlCommand("select * from Customers", con)
cmd.Connection.Open()
Dim reader As SqlDataReader
reader = cmd.ExecuteReader()
datagrid1.DataSource = reader
datagrid1.DataBind()
cmd.Connection.Close()
End If
thanks in advanced
-
February 4th, 2006, 06:26 AM
#2
Re: connect to sql server
i would tried it this way
Code:
Dim con As SqlConnection = New SqlConnection ("Server=localhost;Database = Northwind;Integrated Security = SSPI;")
Dim da As New SqlDataAdapter()
Dim dataset As New DataSet()
Dim cmd As SqlCommand = New SqlCommand("select * from Customers", con)
cmd.Connection.Open()
da.SelectCommand = cmd
da.Fill(DataSet, "Customers")
Me.DataGrid1.SetDataBinding(dataset, "Customers")
cmd.Connection.Close()
-
February 4th, 2006, 06:49 AM
#3
Re: connect to sql server
im getting an error on SetDataBinding so i tried to use dataSource+dataBind
but its still not working, i cant see anything.
what else can it be?
-
February 4th, 2006, 07:24 AM
#4
Re: connect to sql server
-
February 4th, 2006, 07:35 AM
#5
Re: connect to sql server
'SetDataBinding' is not a member of 'System.Web.UI.WebControls.DataGrid'
-
February 5th, 2006, 04:35 AM
#6
Re: connect to sql server
try this instead of
Code:
datagrid1.dataBind
Me.dataBind
-
February 5th, 2006, 06:20 AM
#7
Re: connect to sql server
Take a look at this Sample
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|