CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2005
    Posts
    178

    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

  2. #2
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    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()

  3. #3
    Join Date
    May 2005
    Posts
    178

    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?

  4. #4
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: connect to sql server

    whts the error

  5. #5
    Join Date
    May 2005
    Posts
    178

    Re: connect to sql server

    'SetDataBinding' is not a member of 'System.Web.UI.WebControls.DataGrid'

  6. #6
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: connect to sql server

    try this instead of
    Code:
    datagrid1.dataBind
    Me.dataBind

  7. #7
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    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
  •  





Click Here to Expand Forum to Full Width

Featured