Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to update DataGrid

Status
Not open for further replies.

GerardMcL

Technical User
Aug 5, 2004
212
IE
Hi,
I am saving a record and trying to update the data in the datagrid, BUT alas things are not running smooth and I havent learnt all the errors yet. Heres my code

Dim da As OleDbDataAdapter
Dim dt As DataTable
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

da = New OleDbDataAdapter("Select * from Tools", cn)
dt = New DataTable
da.Fill(dt)

dg.DataSource = dt


Dim drow As System.Data.DataRow
drow = dt.NewRow()

drow.Item("ToolID") = tID
drow.Item("Description") = Desc
drow.Item("Price") = Price
drow.Item("CompanyID") = cID
drow.Item("BoughtDate") = bDate

dt.Rows.Add(drow)

I get the error on the code da = New OleDbDataAdapter("Select * from Tools", cn)

the error reads SelectCommand.Connection property has not been initialised. Anyone know why????
Ph and if anyone spots a future error dont be shy in pointing it out.

Thank You very much.
 
First of all...you haven't initialized the connection object.
cn = new OleDbConnection
Check your code...It's not a good practise to define so many variables without using them.

Sharing the best from my side...

--Prashant--
 
D'OH

Cheers for that! Now to problem two: (This is a module)
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Odbc
Imports ADODB


Public Class Form1
Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

The public class Form1 line gives me a problem, "Input line was not in correct format
 
I am not getting exact picture of your code and so the scenario of the error that you are getting now. I think the error should 'input string not in correct format' not 'Input line was not in correct format'...is it ok?
The main cause: The code is expecting an integet and you are passing a string. Check the code...

Sharing the best from my side...

--Prashant--
 
Sorry its in my module:

Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Odbc
Imports ADODB

Public Class Form1
Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
.....


And sorry it did say "input string"
Im passing a Grid using ByRef dg As DataGrid

Dim varDGrid As DataGrid
varDGrid = Me.dgTools
Call Add_Tools_DataGrid(varToolID, varDesc, varPrice, varBDate, varCompID, varDGrid)

Maybe the problems lies here - I have tried a few things but had no luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top