can someone help me find out what could be missing in this code?
NOTE: I took other codes supposelly working from other internet sources and I copied it to my project and it would not work either. could I be missing something in my setup?
Try
'========================================= ADO INSTANTIATION ===================================================
Dim cmdSelect As New SqlCommand
Dim thisDataSet As New DataSet
Dim pSQL_Conn As New SqlConnection 'CONNECTION OBJECT
Dim cmdInsert As New SqlCommand 'COMMAND OBJECT TO PERFOM QUERIES SUCH AS INSERT, UPDATE AND SELECT
Dim pSQL_Adapter As New SqlDataAdapter 'DATA ADAPTER TO PERFORM ACTUAL CHANGES TO DATABASE
'===============================================================================================================
'===============================================================================================================
'ASSIGNS CONNECTION STRING TO THE CONNECTION STRING OBJECT. IT USES A GLOBAL VARIABLES WHICH GETS IT VALUE
'FROM THE SPLASH SCREEN. THIS IS IN CASE WE MIGRATE TO ANOTHER SERVER URL ALL WE HAVE TO DO IS CHANGE
'THE TEXT FILE LOCATED IN THE ATP ASSISTANT SERVER
'---------------------------------------------------------------------------------------------------------------
pSQL_Conn.ConnectionString =
"Data Source=MSSQL1\SERVER;Integrated Security=True;Initial Catalog=ATP_Data;Connection Timeout=30"
'===============================================================================================================
'===============================================================================================================
'ASSIGNS SQL STATEMENT TO THE COMMAND OBJECT
cmdSelect.CommandText =
"SELECT * FROM tblTableName"
'===============================================================================================================
'===============================================================================================================
'ASSIGNS CONNECTION STRING TO THE CONNECTION OBJECT
cmdSelect.Connection = pSQL_Conn
'===============================================================================================================
'===============================================================================================================
'ASSIGNS COMMAND TEXT OBJECT TO THE DATA ADAPTER
pSQL_Adapter.SelectCommand = cmdSelect
'===============================================================================================================
'===============================================================================================================
pSQL_Conn.Open()
'OPENS THE CONNECTION TO DATABASE STATED ON THE CONNECTION STRING
'===============================================================================================================
'===============================================================================================================
Dim sqlBuilder As New SqlCommandBuilder(pSQL_Adapter) 'INSTANTIATE NEW BUILDER AND ASSIGNS THE ADAPTER
'===============================================================================================================
'===============================================================================================================
pSQL_Adapter.Fill(thisDataSet,
"MyTable") 'FILLS DATA SET
'===============================================================================================================
MsgBox(thisDataSet.Tables(
"MyTable").Rows(0)("fldCompletionDate").ToString)' Set up the DataGridView.
With Me.DataGridView2' Automatically generate the DataGridView columns.
.AutoGenerateColumns =
True
' Set up the data source.
'bindingSource1.DataSource = thisDataSet
.DataSource = thisDataSet
' Automatically resize the visible rows.
.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders' Set the DataGridView control's border.
.BorderStyle =
BorderStyle.Fixed3D' Put the cells in edit mode when user enters them.
.EditMode =
DataGridViewEditMode.EditOnEnterEnd With
Catch ex As SqlException
MsgBox(ex)
End Try
Thank you all.
Suthish NairPosted Apr 14, 2011, 4:18 PM
refer articles, might you missing something.
How to load data from database into DataGridView in VB.NET
Also, this in c#
DataGridView - Insert, Update, Delete and Retrieve records using stored procedure