|
 |
aspx_beginners thread: Updating Access 2000 Database with ASP.NET and DataList
Message #1 by steveproctor@c... on Sun, 16 Jun 2002 18:42:29
|
|
Can anyone help with the following code snippet? It's intended to update
an Access 2000 database using DataList? The error is in the
line "objInitialsParam.Value = txtInitials.Text" and the error message
is : Exception Details: System.NullReferenceException: Object reference
not set to an instance of an object.
Sub dlstRMChecks_UpdateCommand( s As Object, e As
DataListCommandEventArgs )
Dim Conn As OleDbConnection
Dim strUpdate As String
Dim cmdUpdate as OleDbCommand
Dim strForm As String
Dim txtInitials As TextBox
Dim txtTo As TextBox
Dim txtForm As TextBox
Dim strInitials as String
Dim strTo as String
Dim objInitialsParam as OleDbParameter
Dim objToParam as OleDbParameter
Dim objFormParam as OleDbParameter
strForm = dlstRMChecks.DataKeys( e.Item.ItemIndex )
'HERE I OPEN THE CONNECTION, WHICH IS NOT THE PROBLEM
strUpdate = "Update RMChecks Set Initials= @Initials, To = @To
Where Form=@Form"
cmdUpdate = New OleDbCommand( strUpdate, Conn )
objInitialsParam = cmdUpdate.Parameters.Add( "@Initials",
OleDbType.Char )
objInitialsParam.Direction = ParameterDirection.Input
objInitialsParam.Value = txtInitials.Text
objToParam = cmdUpdate.Parameters.Add( "@To", OleDbType.Char )
objToParam.Direction = ParameterDirection.Input
objToParam.Value = txtTo.Text
objFormParam = cmdUpdate.Parameters.Add ("@Form", OleDbType.Char )
objFormParam.Direction = ParameterDirection.Input
objFormParam.Value = strForm
Conn.Open
cmdUpdate.ExecuteNonQuery()
Conn.Close()
dlstRMChecks.EditItemIndex = -1
BindDataList
End Sub
A portion of the UI is:
<EditItemTemplate>
<tr>
<td>
<asp:TextBox
ID="txtInitials"
Text='<%# Container.DataItem( "Initials" )
%>'
Runat="Server" />
</td>
<td>
<asp:TextBox
ID="txtTo"
Text='<%# Container.DataItem( "To" ) %>'
Runat="Server" />
</td>
<td>
<asp:TextBox
ID="txtForm"
Text='<%# Container.DataItem( "Form" ) %>'
Runat="Server" />
</td>
</tr>
Thanks for any help.
Steve
Message #2 by David Barnes <DavidB@w...> on Mon, 17 Jun 2002 11:41:59 +0100
|
|
Hi Steve
Is the VB.NET code in a separate file from the ASP.NET stuff (e.g. using the
codebehind= or src= attribute in the ASPX file's Page directive)? If so, I
think that any objects that you want to use in both the code and the ASP.NET
need to be declared as:
Protected WithEvents txtTo As TextBox
The code-behind is a different .NET class from the ASPX. The ASP.NET
interpreter converts the ASPX into a .NET class that inherits from the
code-behind class. If you want to use variables in both classes then they
must be declared as Protected in the base class. Otherwise .NET thinks of
them as two different variables.
I'm not 100% sure about this solution though ... I'd be interested to know
if it works. :)
Regards
David Barnes
Wrox Editor
--
So You'd Like to Program ASP.NET Websites?
http://www.amazon.com/exec/obidos/tg/guides/guide-display/-/YAEJ7I55O1ED/104
-0520375-7947930
> -----Original Message-----
> From: steveproctor@c... [mailto:steveproctor@c...]
> Sent: 16 June 2002 19:42
> To: aspx_beginners
> Subject: [aspx_beginners] Updating Access 2000 Database with
> ASP.NET and
> DataList
>
>
> Can anyone help with the following code snippet? It's
> intended to update
> an Access 2000 database using DataList? The error is in the
> line "objInitialsParam.Value = txtInitials.Text" and the
> error message
> is : Exception Details: System.NullReferenceException: Object
> reference
> not set to an instance of an object.
>
>
>
> Sub dlstRMChecks_UpdateCommand( s As Object, e As
> DataListCommandEventArgs )
> Dim Conn As OleDbConnection
> Dim strUpdate As String
> Dim cmdUpdate as OleDbCommand
> Dim strForm As String
> Dim txtInitials As TextBox
> Dim txtTo As TextBox
> Dim txtForm As TextBox
> Dim strInitials as String
> Dim strTo as String
>
> Dim objInitialsParam as OleDbParameter
> Dim objToParam as OleDbParameter
> Dim objFormParam as OleDbParameter
>
> strForm = dlstRMChecks.DataKeys( e.Item.ItemIndex )
>
>
> 'HERE I OPEN THE CONNECTION, WHICH IS NOT THE PROBLEM
> strUpdate = "Update RMChecks Set Initials= @Initials, To = @To
> Where Form=@Form"
>
> cmdUpdate = New OleDbCommand( strUpdate, Conn )
>
> objInitialsParam = cmdUpdate.Parameters.Add( "@Initials",
> OleDbType.Char )
> objInitialsParam.Direction = ParameterDirection.Input
> objInitialsParam.Value = txtInitials.Text
>
> objToParam = cmdUpdate.Parameters.Add( "@To", OleDbType.Char )
> objToParam.Direction = ParameterDirection.Input
> objToParam.Value = txtTo.Text
>
> objFormParam = cmdUpdate.Parameters.Add ("@Form",
> OleDbType.Char )
> objFormParam.Direction = ParameterDirection.Input
> objFormParam.Value = strForm
>
> Conn.Open
> cmdUpdate.ExecuteNonQuery()
> Conn.Close()
> dlstRMChecks.EditItemIndex = -1
> BindDataList
> End Sub
>
> A portion of the UI is:
>
> <EditItemTemplate>
> <tr>
> <td>
> <asp:TextBox
> ID="txtInitials"
> Text='<%# Container.DataItem(
> "Initials" )
> %>'
> Runat="Server" />
> </td>
> <td>
> <asp:TextBox
> ID="txtTo"
> Text='<%# Container.DataItem( "To" ) %>'
> Runat="Server" />
> </td>
> <td>
> <asp:TextBox
> ID="txtForm"
> Text='<%# Container.DataItem(
> "Form" ) %>'
> Runat="Server" />
> </td>
> </tr>
>
> Thanks for any help.
>
> Steve
>
Message #3 by steveproctor@c... on Sun, 23 Jun 2002 13:32:34
|
|
David,
Thanks for the reply. But I'm not using any code behind for this
application, so I don't think that's the problem.
Steve
> Can anyone help with the following code snippet? It's intended to
update
a> n Access 2000 database using DataList? The error is in the
l> ine "objInitialsParam.Value = txtInitials.Text" and the error message
i> s : Exception Details: System.NullReferenceException: Object reference
n> ot set to an instance of an object.
>
> Sub dlstRMChecks_UpdateCommand( s As Object, e As
D> ataListCommandEventArgs )
> Dim Conn As OleDbConnection
> Dim strUpdate As String
> Dim cmdUpdate as OleDbCommand
> Dim strForm As String
> Dim txtInitials As TextBox
> Dim txtTo As TextBox
> Dim txtForm As TextBox
> Dim strInitials as String
> Dim strTo as String
>
> Dim objInitialsParam as OleDbParameter
> Dim objToParam as OleDbParameter
> Dim objFormParam as OleDbParameter
>
> strForm = dlstRMChecks.DataKeys( e.Item.ItemIndex )
>
>
> 'HERE I OPEN THE CONNECTION, WHICH IS NOT THE PROBLEM
> strUpdate = "Update RMChecks Set Initials= @Initials, To = @To
W> here Form=@Form"
>
> cmdUpdate = New OleDbCommand( strUpdate, Conn )
>
> objInitialsParam = cmdUpdate.Parameters.Add( "@Initials",
O> leDbType.Char )
> objInitialsParam.Direction = ParameterDirection.Input
> objInitialsParam.Value = txtInitials.Text
>
> objToParam = cmdUpdate.Parameters.Add( "@To", OleDbType.Char )
> objToParam.Direction = ParameterDirection.Input
> objToParam.Value = txtTo.Text
>
> objFormParam = cmdUpdate.Parameters.Add ("@Form",
OleDbType.Char )
> objFormParam.Direction = ParameterDirection.Input
> objFormParam.Value = strForm
>
> Conn.Open
> cmdUpdate.ExecuteNonQuery()
> Conn.Close()
> dlstRMChecks.EditItemIndex = -1
> BindDataList
E> nd Sub
> A portion of the UI is:
> <EditItemTemplate>
> <tr>
> <td>
> <asp:TextBox
> ID="txtInitials"
> Text='<%# Container.DataItem( "Initials" )
%> >'
> Runat="Server" />
> </td>
> <td>
> <asp:TextBox
> ID="txtTo"
> Text='<%# Container.DataItem( "To" ) %>'
> Runat="Server" />
> </td>
> <td>
> <asp:TextBox
> ID="txtForm"
> Text='<%# Container.DataItem( "Form" ) %>'
> Runat="Server" />
> </td>
> </tr>
> Thanks for any help.
> Steve
Message #4 by "Maui Namahoe" <jmnamahoe@h...> on Mon, 24 Jun 2002 10:13:39 -1000
|
|
here is a debugging suggestion that i use to find where i might have gone
wrong. what i would do is build the SQL statment from scratch and then
assign it to a string variable. then create a label on your form. create
your connections to your DB and then implement the 'bind' of data within a
'try..catch' statment. include inside the 'try..catch' statement the new
label. with in the 'try' portion of the statement pass a string to label
acknowledgment that the process is going correctly. on the flip side, with
in the 'catch' portion of the statement, pump in the SQL statment that you
wrote. i find this helpfull because nine times out of ten the connection to
the db is correct but there is something wrong with my SQL statement. this
way you can see for the most part that you are doing stuff correct. i know
that there is nothing more iritating than not being able to see what is
wrong with your code.
----- Original Message -----
From: <steveproctor@c...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Sunday, June 23, 2002 1:32 PM
Subject: [aspx_beginners] Re: Updating Access 2000 Database with ASP.NET and
DataList
> David,
>
> Thanks for the reply. But I'm not using any code behind for this
> application, so I don't think that's the problem.
>
> Steve
>
> > Can anyone help with the following code snippet? It's intended to
> update
> a> n Access 2000 database using DataList? The error is in the
> l> ine "objInitialsParam.Value = txtInitials.Text" and the error message
> i> s : Exception Details: System.NullReferenceException: Object reference
> n> ot set to an instance of an object.
>
> >
>
> > Sub dlstRMChecks_UpdateCommand( s As Object, e As
> D> ataListCommandEventArgs )
> > Dim Conn As OleDbConnection
> > Dim strUpdate As String
> > Dim cmdUpdate as OleDbCommand
> > Dim strForm As String
> > Dim txtInitials As TextBox
> > Dim txtTo As TextBox
> > Dim txtForm As TextBox
> > Dim strInitials as String
> > Dim strTo as String
> >
> > Dim objInitialsParam as OleDbParameter
> > Dim objToParam as OleDbParameter
> > Dim objFormParam as OleDbParameter
> >
> > strForm = dlstRMChecks.DataKeys( e.Item.ItemIndex )
> >
> >
> > 'HERE I OPEN THE CONNECTION, WHICH IS NOT THE PROBLEM
> > strUpdate = "Update RMChecks Set Initials= @Initials, To = @To
> W> here Form=@Form"
> >
> > cmdUpdate = New OleDbCommand( strUpdate, Conn )
> >
> > objInitialsParam = cmdUpdate.Parameters.Add( "@Initials",
> O> leDbType.Char )
> > objInitialsParam.Direction = ParameterDirection.Input
> > objInitialsParam.Value = txtInitials.Text
> >
> > objToParam = cmdUpdate.Parameters.Add( "@To", OleDbType.Char )
> > objToParam.Direction = ParameterDirection.Input
> > objToParam.Value = txtTo.Text
> >
> > objFormParam = cmdUpdate.Parameters.Add ("@Form",
> OleDbType.Char )
> > objFormParam.Direction = ParameterDirection.Input
> > objFormParam.Value = strForm
> >
> > Conn.Open
> > cmdUpdate.ExecuteNonQuery()
> > Conn.Close()
> > dlstRMChecks.EditItemIndex = -1
> > BindDataList
> E> nd Sub
>
> > A portion of the UI is:
>
> > <EditItemTemplate>
> > <tr>
> > <td>
> > <asp:TextBox
> > ID="txtInitials"
> > Text='<%# Container.DataItem( "Initials" )
> %> >'
> > Runat="Server" />
> > </td>
> > <td>
> > <asp:TextBox
> > ID="txtTo"
> > Text='<%# Container.DataItem( "To" ) %>'
> > Runat="Server" />
> > </td>
> > <td>
> > <asp:TextBox
> > ID="txtForm"
> > Text='<%# Container.DataItem( "Form" ) %>'
> > Runat="Server" />
> > </td>
> > </tr>
>
> > Thanks for any help.
>
> > Steve
>
|
|
 |