1

How to load data from database table and display in datagrid in VB.NET? I know how it is in C#. I am not familiar with vb.net. Any help will be appreciated.

3
  • 1
    if you know C# then link try this Commented Feb 2, 2012 at 10:09
  • MSDN shows you also in VB.NET how it works. Commented Feb 2, 2012 at 10:15
  • datagrid is what? ASP.NET, WinForm or WPF Control? Commented Feb 2, 2012 at 12:00

1 Answer 1

3

Try the following:-

    Imports System.Data.SqlClient

In your event, write:-

    Dim con As SqlConnection

    Dim ada As New SqlDataAdapter()
    Dim ds As New DataSet

    con = New SqlConnection("server=localhost;uid=sa;pwd=;database=databasename")
    con.Open()


    ada = New SqlDataAdapter("Select * from tablename", con)
    ada.Fill(ds)
    DataGridView1.DataSource = ds.Tables(0)

I think this will solve your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

@Sun if my solution helps you to solve your problem, please accept it as your answer by clicking the check sign.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.