473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ASP.NET/C#->MS SQL help

Hi,
I have trouble with the following:
I have this Stored Procedure:
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'prUPUSERINFO' AND type = 'P')
DROP PROCEDURE prUPUSERINFO
GO
CREATE PROCEDURE prUPUSERINFO
@USRNAME VARCHAR(20),
@NAME VARCHAR(64),
@CITY VARCHAR(20),
@PHONE VARCHAR(16),
@ADDR VARCHAR(74),
@EML VARCHAR(64)
AS
UPDATE BLEK.USERS
SET
RealName=@NAME,UserCity=@CITY,UserPhone=@PHONE,Use rAddr=@ADDR,UserEmail=@EML
WHERE Username=@USRNAME

When I execute it everythings is fine.
I develop ASP.NET C# Application
and do the following in one of the forms:

private void InsertBtn_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter dada = new SqlDataAdapter("UPDATE BLEK.USERS SET
RealName=@NAME,UserCity=@CITY,UserPhone=@PHONE,Use rAddr=@ADDR,UserEmail=@EML
WHERE Username=@USRNAME",conn);
dada.UpdateCommand.CommandType = CommandType.Text;
conn.Open();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@USRNAME",
SqlDbType.VarChar,20));
dada.UpdateCommand.Parameters["@USRNAME"].Value = Session["usrName"];
dada.UpdateCommand.Parameters.Add(new SqlParameter("@NAME",
SqlDbType.VarChar,64));
dada.UpdateCommand.Parameters["@NAME"].Value = NameTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@CITY",
SqlDbType.VarChar,20));
dada.UpdateCommand.Parameters["@CITY"].Value = CityTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@PHONE",
SqlDbType.VarChar,16));
dada.UpdateCommand.Parameters["@PHONE"].Value = PhoneTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@ADDR",
SqlDbType.VarChar,74));
dada.UpdateCommand.Parameters["@ADDR"].Value = AddressTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@EML",
SqlDbType.VarChar,64));
dada.UpdateCommand.Parameters["@EML"].Value = EmailTB.Text.Trim();
dada.UpdateCommand.ExecuteNonQuery();
conn.Close();
}
Could you tell me waths the problem here?
When I Push the Button Insert The following error appears:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 104: SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
Line 105: SqlDataAdapter dada = new SqlDataAdapter("UPDATE BLEK.USERS SET
RealName=@NAME,UserCity=@CITY,UserPhone=@PHONE,Use rAddr=@ADDR,UserEmail=@EML
WHERE Username=@USRNAME",conn);
Line 106: dada.UpdateCommand.CommandType = CommandType.Text;
Line 107: conn.Open();
Line 108: dada.UpdateCommand.Parameters.Add(new SqlParameter("@USRNAME",
SqlDbType.VarChar,20));
Source File: c:\inetpub\wwwroot\estates\pdata.aspx.cs Line: 106

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
Estates.pdata.InsertBtn_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\estates\pdata.aspx.cs:106
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()


Thank you very much!

Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 24.8.2004 a.
Nov 18 '05 #1
2 1579

"Viktor Popov" <vi****@yahoo.com> wrote in message news:OG*************@TK2MSFTNGP09.phx.gbl...
[snip]

}
Could you tell me waths the problem here?
When I Push the Button Insert The following error appears:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 104: SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
Line 105: SqlDataAdapter dada = new SqlDataAdapter("UPDATE BLEK.USERS SET
RealName=@NAME,UserCity=@CITY,UserPhone=@PHONE,Use rAddr=@ADDR,UserEmail=@EML
WHERE Username=@USRNAME",conn);
Line 106: dada.UpdateCommand.CommandType = CommandType.Text;
Where did you specify this "UpdateCommand"? The sql text you specify (granted, it IS
an update statement) is used as "SelectCommand" ! Thus there is no UpdateCommand
and you get this error when you try to use it.

use this:
SqlDataAdapter dada = new SqlDataAdapter();
dada.UpdateCommand = new SqlCommand("Update .......", conn);

Hans Kesting

Line 107: conn.Open();
Line 108: dada.UpdateCommand.Parameters.Add(new SqlParameter("@USRNAME",
SqlDbType.VarChar,20));
Source File: c:\inetpub\wwwroot\estates\pdata.aspx.cs Line: 106

Nov 18 '05 #2
Viktor Popov wrote:
Hi,
I have trouble with the following:
I have this Stored Procedure:
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'prUPUSERINFO' AND type = 'P')
DROP PROCEDURE prUPUSERINFO
GO
CREATE PROCEDURE prUPUSERINFO
@USRNAME VARCHAR(20),
@NAME VARCHAR(64),
@CITY VARCHAR(20),
@PHONE VARCHAR(16),
@ADDR VARCHAR(74),
@EML VARCHAR(64)
AS
UPDATE BLEK.USERS
SET
RealName=@NAME,UserCity=@CITY,UserPhone=@PHONE,Use rAddr=@ADDR,UserEmail=@EML
WHERE Username=@USRNAME

When I execute it everythings is fine.
I develop ASP.NET C# Application
and do the following in one of the forms:

private void InsertBtn_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter dada = new SqlDataAdapter("UPDATE BLEK.USERS SET
RealName=@NAME,UserCity=@CITY,UserPhone=@PHONE,Use rAddr=@ADDR,UserEmail=@EML
WHERE Username=@USRNAME",conn);
dada.UpdateCommand.CommandType = CommandType.Text;
conn.Open();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@USRNAME",
SqlDbType.VarChar,20));
dada.UpdateCommand.Parameters["@USRNAME"].Value = Session["usrName"];
dada.UpdateCommand.Parameters.Add(new SqlParameter("@NAME",
SqlDbType.VarChar,64));
dada.UpdateCommand.Parameters["@NAME"].Value = NameTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@CITY",
SqlDbType.VarChar,20));
dada.UpdateCommand.Parameters["@CITY"].Value = CityTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@PHONE",
SqlDbType.VarChar,16));
dada.UpdateCommand.Parameters["@PHONE"].Value = PhoneTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@ADDR",
SqlDbType.VarChar,74));
dada.UpdateCommand.Parameters["@ADDR"].Value = AddressTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@EML",
SqlDbType.VarChar,64));
dada.UpdateCommand.Parameters["@EML"].Value = EmailTB.Text.Trim();
dada.UpdateCommand.ExecuteNonQuery();
conn.Close();
}
Could you tell me waths the problem here?
When I Push the Button Insert The following error appears:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 104: SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
Line 105: SqlDataAdapter dada = new SqlDataAdapter("UPDATE BLEK.USERS SET
RealName=@NAME,UserCity=@CITY,UserPhone=@PHONE,Use rAddr=@ADDR,UserEmail=@EML
WHERE Username=@USRNAME",conn);
Line 106: dada.UpdateCommand.CommandType = CommandType.Text;
Line 107: conn.Open();
Line 108: dada.UpdateCommand.Parameters.Add(new SqlParameter("@USRNAME",
SqlDbType.VarChar,20));
Source File: c:\inetpub\wwwroot\estates\pdata.aspx.cs Line: 106

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
Estates.pdata.InsertBtn_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\estates\pdata.aspx.cs:106
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()


Thank you very much!

Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 24.8.2004 a.

Define your parameters in the same sequence as they are used in the sql
query.

//Rutger
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
5
by: anthonyberet | last post by:
I work for an organisation that uses a bespoke document imaging system, the database of which is an MS sql server. We have MS Access and already use it for some querying of the database. The...
18
by: Rob R. Ainscough | last post by:
MS Visual Studio Ad contained in VS Magazine. Two developers in "hip" clothing diagramming out a huge flow chart on a beach. I could NOT stop laughing at the stupidity of the ad -- "Let your...
5
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I...
92
by: Jeffrey P via AccessMonster.com | last post by:
Our IT guys are on a vendetta against MS Access (and Lotus Notes but they've won that fight). What I can't understand is, what's the problem? Why does IT hate MS Access so much. I have tried...
0
by: com | last post by:
MS Access 2000 Password Recoverer 4.2 Screenshot - Soft30.com MS Access 2000 Password Recoverer will display the password to a MS Access database (*.mdb). This program works for MS Access files...
10
by: Minh | last post by:
I search in all the Disscussion but can not found. How can I create a MS Access Database file using C# code with a given Table Structure ? For example, I want to create a Access Database File...
14
by: kdv09 | last post by:
Hi! I'm looking for some help in fixing my screwup: I've got C++ app which reads MDB database, using MFC CDatabase and CRecordset derived classes. I had it working OK on development PC (Win XP...
6
by: jonefer | last post by:
I have two versions of a 'Downtime Application that will run in the event that the mainframe goes down 1) SQL Server ASP.NET app (accessed outside the mainframe network) 2) MS Access Version of...
4
by: PabsBath | last post by:
Hello, help please. I have been pulling my hair out for a few weeks now and been looking on the web for answers but not managed to find anything!! I'm currently operating a small (2mb - approx...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.