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
Re: Problems connecting to database
What is the error and which line are you getting it on?
Re: Problems connecting to database
da.Fill(ds, "f12")
Sounds like the problem. Hover over it, and report back
1 Attachment(s)
Re: Problems connecting to database
Thank
When I run the program
It gives the error:
Attachment 31825
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
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
Re: Problems connecting to database
thanks my frinds!
resolved problem, from was conection string
Re: Problems connecting to database
Glad you got it solved and shared with us! :thumb: Please mark your thread resolved.
1 Attachment(s)
Re: Problems connecting to database
The problem of the connection string
I connect to the database server using server explorer
Attachment 31849
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:D:D