CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2012
    Posts
    11

    Problems connecting to database

    Hi

    I want to become a bank , but , This line has errors: da.Fill(ds, "f12")

    Where is the problem?
    Thank


    Code:
    Imports System.Data
    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 strsql As String
            Dim strcon As String
            strcon = "Data Source=.;Integrated Security=True"
    
            Dim con As New SqlConnection(strCon)
            con.Open()
            strsql = "select * from f12"
            Dim da As New SqlDataAdapter(strsql, con)
            Dim ds As New DataSet()
            da.Fill(ds, "f12")
            DataGrid1.DataBindings.Add(New Binding("dataource", da, "f12"))
            con.Close()
        End Sub
    End Class
    Last edited by ali 254; September 28th, 2013 at 10:04 AM.

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Problems connecting to database

    What is the error and which line are you getting it on?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Problems connecting to database

    da.Fill(ds, "f12")

    Sounds like the problem. Hover over it, and report back
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Oct 2012
    Posts
    11

    Re: Problems connecting to database

    Thank

    When I run the program
    It gives the error:
    Name:  a9988.jpg
Views: 972
Size:  58.6 KB

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Problems connecting to database

    so the error is telling you where the problem is and what the problem is. I would suggest that you look up the proper way to use the da.fill statement
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Problems connecting to database

    What is F12? A Table? A View?

    Just as a side note: Naming objects are very important! The object's name should reflect what it does, so that you know where is what and what is what in the future. A name such as F12 is really really bad

  7. #7
    Join Date
    Oct 2012
    Posts
    11

    Re: Problems connecting to database

    thanks my frinds!

    resolved problem, from was conection string

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Problems connecting to database

    Glad you got it solved and shared with us! Please mark your thread resolved.

  9. #9
    Join Date
    Oct 2012
    Posts
    11

    Re: Problems connecting to database

    The problem of the connection string
    I connect to the database server using server explorer
    Name:  1.png
Views: 989
Size:  18.3 KB
    Then,I wrote this code:


    Code:
    Imports System.Data
    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 strsql As String
            Dim strcon As String
    
            strcon = "Data Source=.;Initial Catalog=student;Integrated Security=True"
    
            Dim con As New SqlConnection(strcon)
            con.Open()
            strsql = "select * from stTAble1"
            Dim da As New SqlDataAdapter(strsql, con)
            Dim ds As New DataSet()
            da.Fill(ds, "sttable1")
            DataGrid1.DataBindings.Add(New Binding("datasource", ds, "sttable1"))
            con.Close()
        End Sub
    
        
    End Class
    The problem was solved
    Last edited by ali 254; October 1st, 2013 at 02:08 PM.

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