datagridview and DB Firebird

ElCondorVola

New member
Joined
Jul 17, 2015
Messages
1
Programming Experience
Beginner
Hello everyone.
I am developing a Windows Forms application with Visual Studio 2010 and VB.net
on the "load" of a form I inserted the following code that takes data from a Firebird DB and I would populate a "datagridview" but I can not:

VB.NET:
 Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        Try
            Dim cn As New OdbcConnection("dsn=PHOENIXDB;uid=SYSDBA;pwd=masterkey;")
            Dim mystring As String = "Select * from VW_SSN_REGIONI"
            Dim cmd As OdbcCommand = New OdbcCommand(mystring)
            Dim daSSNregioni As New OdbcDataAdapter


            Dim dsSSNregioni As New DataSet
            cn.Open()


            daSSNregioni.SelectCommand = cmd
            daSSNregioni.SelectCommand.Connection = cn
            daSSNregioni.Fill(dsSSNregioni, "SSN_REGIONI")
            Me.DataGridViewX1.DataSource = dsSSNregioni




            cn.Close()
        Catch ex As NullReferenceException
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
        End Try




    End Sub

You can help me?
Thanks
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,742
Location
Sydney, Australia
Programming Experience
10+
What does "can not" actually mean? You have code there. Presumably your are executing the code. What happens? If there's an exception thrown then don't keep that a secret. The information it provides is for diagnostic purposes and you're asking us to diagnose the issue.

That said, I can an issue with your code. You populate a DataTable named "SSN_REGIONI" when you call Fill but you don't tell the grid anything about that when you bind. If you're going to bind a DataSet then you have to assign the name of the table to the DataMember property. Why bind a DataSet in the first place though? You're only using one DataTable so just create a DataTable. Populate that DataTable and bind it directly. You don't create an array for one String so don't create a DataSet for one DataTable.
 
Top Bottom