ralucutza77
New member
- Joined
- Feb 7, 2007
- Messages
- 4
- Programming Experience
- Beginner
Hello,
I’m a begginer and I know that my question might sound stupid…So, what I’m trying to do, in a windows application, is connect to a SQL data base and display in a datagridview 4 columns from one table of that database. Well, my datagridview is empty and I don’t know what is the problem. What is the role of the BindingSource? Should I use it?
Here is the code:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myCon As New SqlConnection
Dim da As SqlDataAdapter
Dim ds As New DataSet
myCon.ConnectionString = "server = (local); database=Gigi;trusted_connection=true "
da = New SqlDataAdapter("select Date, TotalValue, Number, ID from bills", myCon)
myCon.Open()
da.Fill(ds)
Grid1.Columns.Add("Date", "Data factura")
Grid1.Columns.Add("Value", "Valoare totala")
Grid1.Columns.Add("Number", "Numar factura")
Grid1.Columns.Add("ID", "Serie factura")
Grid1.DataSource = ds.Tables(0).DefaultView
myCon.Close()
End Sub
Thanks!
I’m a begginer and I know that my question might sound stupid…So, what I’m trying to do, in a windows application, is connect to a SQL data base and display in a datagridview 4 columns from one table of that database. Well, my datagridview is empty and I don’t know what is the problem. What is the role of the BindingSource? Should I use it?
Here is the code:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myCon As New SqlConnection
Dim da As SqlDataAdapter
Dim ds As New DataSet
myCon.ConnectionString = "server = (local); database=Gigi;trusted_connection=true "
da = New SqlDataAdapter("select Date, TotalValue, Number, ID from bills", myCon)
myCon.Open()
da.Fill(ds)
Grid1.Columns.Add("Date", "Data factura")
Grid1.Columns.Add("Value", "Valoare totala")
Grid1.Columns.Add("Number", "Numar factura")
Grid1.Columns.Add("ID", "Serie factura")
Grid1.DataSource = ds.Tables(0).DefaultView
myCon.Close()
End Sub
Thanks!