locked
VB.Net Windows Form - Cannot load data to DatagridView RRS feed

  • Question

  • It's been 19 years since I developed a windows form using VB. I've only done web development since. So I'm a little rusty. So I created a windows form and dragged a DataGridView control to my form. I then added 2 columns. I have a class library where I have a function that returns a datatable. This works as I use it on a web form. But when I run my windows form, I get the DataGridView with no data. Here is my code: 

    Imports System.Configuration 
    Imports OrdersClasses 
    Public Class Form1 
       Dim connStringNW As String = ConfigurationManager.ConnectionStrings("MRInw").
       ConnectionString Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As       System.EventArgs) Handles MyBase.Load 
       dgvOrders.DataSource = GetDataTable() 
    End Sub

    Private Function GetDataTable() As DataTable 

       Dim oOrder As New Order(connStringNW)
       Dim dt As New DataTable() 
       dt = oOrder.GetOrderByStatusCode("I")
       Return dt 
    End Function 
    End Class 


    This method works perfectly on my web form: objOrder.GetOrderByStatusCode("I") So what am I doing wrong? Why is my DataGridView not displaying my data?

    • Moved by Tina-Shi Wednesday, May 13, 2015 7:41 AM the issue is related to this windows form
    Tuesday, May 12, 2015 12:02 PM

Answers

  • Please check whether the value of "connStringNW" is received by function "GetDataTable".

    I'm afraid it is not.

    • Proposed as answer by Youjun Tang Wednesday, May 13, 2015 7:54 AM
    • Marked as answer by Youjun Tang Tuesday, June 9, 2015 9:36 AM
    Tuesday, May 12, 2015 6:37 PM

All replies

  • Please check whether the value of "connStringNW" is received by function "GetDataTable".

    I'm afraid it is not.

    • Proposed as answer by Youjun Tang Wednesday, May 13, 2015 7:54 AM
    • Marked as answer by Youjun Tang Tuesday, June 9, 2015 9:36 AM
    Tuesday, May 12, 2015 6:37 PM
  • Hi BH052699,

    Thank you for posting in MSND forum.

    Since this issue is related to this Windows Form, so we will move this case to this Windows Form Forum, you will get better support.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, May 13, 2015 7:40 AM