Hello,
Thanks in advance for any insight you can offer. I've a ASP.NET project
written in C#, two web forms, a lovely gob of using statements. I originally
had one webform with all my fields and datagrid stacked, and thought it would
be cleaner to server.transfer to another webform when I wanted to submit a
new record. When I had just one webform this same syntax worked fine. But now
that I'm not on the same webform as where the datagrid resides, I had to
change the code to use a sqlCommand. I am not presently getting an error, and
it builds fine. (By the way, I did turn off the custom error messages but it
doesn't give me the full error page.)
Earlier on I was getting errors like 'input string not in correct format',
but those seemed to have cleared. I also got an error that was a null object
reference and I seem to have resolved that too.
again thanks,
Samantha
try
{
SqlConnection sqlCon6 = new SqlConnection(
"Server=DP05900 ;database=InfoS vcs_ServerLogs; uid=sa;password =cr3ati0n;");
SqlCommand sqlAddLog = new SqlCommand ("sqlAddLog" , sqlCon6);
sqlCon6.Open();
sqlAddLog.Comma ndType = CommandType.Sto redProcedure;
sqlAddLog.Comma ndText = ("exec sqlAddLog");
sqlAddLog.Param eters.Add("@Ass igned_To",Syste m.Data.SqlDbTyp e.VarChar,20).V alue = ddlAdmins.Selec tedItem.Text; ;
sqlAddLog.Param eters.Add("@Ent ry_Date_Time",S ystem.Data.SqlD bType.DateTime, 8).Value = TxtDate.Text;
sqlAddLog.Param eters.Add("@Com ments",System.D ata.SqlDbType.V arChar,5000).Va lue = TxtAction.Text;
sqlAddLog.Param eters.Add("@Ser ver_Id",System. Data.SqlDbType. Int).Value =
ddlServers.Sele ctedValue;
Console.WriteLi ne();
sqlCon6.Close() ;
// Server.Transfer ("ControlPanel. aspx");
}
catch ( System.Exceptio n Ex )
{
Console.WriteLi ne();
LblError.Text =
Ex.Message;
}
finally
{
if (sqlCon6 != null)
sqlCon6.Close() ;
}
} 7 2542
You don't mention what the problem is but just glancing at it I see a
few things wrong.
1.) No call to ExecuteNonQuery () on the command object so no call to
the database to update/insert will ever be made.
2.) You try to reference your SqlCon6 object in the finally block but
it is defined in the try block so won't be visible to the finally
block. Define it above the try block as SqlConnection sqlCon6 = null;
3.) You have a call to sqlCon6.Close() in both your try block and your
finally block, it is only needed in your finally block.
Oops, I missed the line
sqlAddLog.Comma ndText = ("exec sqlAddLog");
Get rid of it, your define the command text correctly in the first
parameter of the constructor.
Thanks.
1. I commented out the sqlAddLog.Comma ndText = ("exec sqlAddLog");
2. I couldn't add the sqlCon6 = null above the try since it wouldn't build
.... saying it would cause sqlCon6 to mean something other than what it
currently meant.
3. I commented out the sqlCon6.Close() ; that is found in my try statement.
4. Now I am getting the original error, which I'd thought I'd eliminated ...
Object reference not set to an instance of an object.
I've read a great deal of Google and MSDN posts on this. I know its a
"newbie error" but for the life of me, I can't see what I've not instantiated.
Thanks again.
"sd********@gma il.com" wrote: Oops, I missed the line sqlAddLog.Comma ndText = ("exec sqlAddLog"); Get rid of it, your define the command text correctly in the first parameter of the constructor.
Also, I didn't specify that the code, written as it was originally, didn't
generate an error nor did it create a row in the database. The stored
procedure works fine both through Query Analyzer and also when referenced in
my original code.
Thanks,
S
"sd********@gma il.com" wrote: Oops, I missed the line sqlAddLog.Comma ndText = ("exec sqlAddLog"); Get rid of it, your define the command text correctly in the first parameter of the constructor.
It should look similar to this (I can't try compiling myself right now,
not on a dev machine):
SqlConnection sqlCon6 = null;
try
{
sqlCon6 = new
SqlConnection(" Server=DP05900; database=InfoSv cs_ServerLogs;u id=sa;password= cr3ati0n;");
SqlCommand sqlAddLog = new SqlCommand ("sqlAddLog" ,
sqlCon6);
sqlCon6.Open();
sqlAddLog.Comma ndType = CommandType.Sto redProcedure;
sqlAddLog.Param eters.Add("@Ass igned_To",Syste m.Data.SqlDbTyp e.VarChar,20).V alue
= ddlAdmins.Selec tedItem.Text; ;
sqlAddLog.Param eters.Add("@Ent ry_Date_Time",S ystem.Data.SqlD bType.DateTime,
8).Value = TxtDate.Text;
sqlAddLog.Param eters.Add("@Com ments",System.D ata.SqlDbType.V arChar,5000).Va lue
= TxtAction.Text;
sqlAddLog.Param eters.Add("@Ser ver_Id",System. Data.SqlDbType. Int).Value
=
ddlServers.Sele ctedValue;
sqlAddLog.Execu teNonQuery();
}
catch ( System.Exceptio n Ex )
{
LblError.Text =
Ex.Message;
}
finally
{
if (sqlCon6 != null)
sqlCon6.Close() ;
}
}
That exception you're seeing is pretty ambiguous, which line exactly is
causing it (turn on "break into debugger" for all exceptions by hitting
alt-ctr-e, highlighting clr exceptions, then selecting break into
debugger from the radio buttons).
Hi,
remove this line:
sqlAddLog.Comma ndText = ("exec sqlAddLog");
You do not call any executing method once you have your parameters, you have
to call one of:
ExecuteReader
ExecuteScalar
ExecuteNonQuery
depending of what you want to return.
after that you should check your DB and see if the row was inserted.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Samantha Penhale" <Sa************ *@discussions.m icrosoft.com> wrote in
message news:B9******** *************** ***********@mic rosoft.com... Hello,
Thanks in advance for any insight you can offer. I've a ASP.NET project written in C#, two web forms, a lovely gob of using statements. I originally had one webform with all my fields and datagrid stacked, and thought it would be cleaner to server.transfer to another webform when I wanted to submit a new record. When I had just one webform this same syntax worked fine. But now that I'm not on the same webform as where the datagrid resides, I had to change the code to use a sqlCommand. I am not presently getting an error, and it builds fine. (By the way, I did turn off the custom error messages but it doesn't give me the full error page.)
Earlier on I was getting errors like 'input string not in correct format', but those seemed to have cleared. I also got an error that was a null object reference and I seem to have resolved that too.
again thanks,
Samantha try
{ SqlConnection sqlCon6 = new SqlConnection( "Server=DP05900 ;database=InfoS vcs_ServerLogs; uid=sa;password =cr3ati0n;"); SqlCommand sqlAddLog = new SqlCommand ("sqlAddLog" , sqlCon6); sqlCon6.Open();
sqlAddLog.Comma ndType = CommandType.Sto redProcedure; sqlAddLog.Comma ndText = ("exec sqlAddLog");
sqlAddLog.Param eters.Add("@Ass igned_To",Syste m.Data.SqlDbTyp e.VarChar,20).V alue = ddlAdmins.Selec tedItem.Text; ; sqlAddLog.Param eters.Add("@Ent ry_Date_Time",S ystem.Data.SqlD bType.DateTime, 8).Value = TxtDate.Text; sqlAddLog.Param eters.Add("@Com ments",System.D ata.SqlDbType.V arChar,5000).Va lue = TxtAction.Text; sqlAddLog.Param eters.Add("@Ser ver_Id",System. Data.SqlDbType. Int).Value = ddlServers.Sele ctedValue;
Console.WriteLi ne(); sqlCon6.Close() ;
// Server.Transfer ("ControlPanel. aspx");
}
catch ( System.Exceptio n Ex ) { Console.WriteLi ne();
LblError.Text = Ex.Message; }
finally { if (sqlCon6 != null) sqlCon6.Close() ; } }
Perfecto! Thank you so much! Now I understand both of the major changes...
sqlConnection sqlCon6 = null;
sqlAddLog.Execu teNonQuery();
The syntax you gave me worked perfectly.
Samantha This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bruno Alexandre |
last post by:
Hi guys,
withou using SP, I want to be able to add a Parameter to the SQL Query and
retrive the Recordset so I can use the Paging property under the recorset
object.... how can I do this?
I'm stuck here.
|
by: Tom |
last post by:
I want to open a recordset object on an .asp page. When I open the
recordset I would like to use a stored procedure that expects a parameter to
be passed for the stored procedure. I will then use the recordset to loop
thru the recordset, update values from the recordset and then update the
database by passing parmeters to another stored...
|
by: Sandie Towers |
last post by:
We use a number of similar databases and frequently create a new
database using a backup restore of another similar database. We try to
keep changes between databases in _Additional tables - like Account
Additional, Sale_Additional so most tables stay the same. The latest
restored database (I'll call it DBaseA) is behaving differently in VB6...
|
by: Rittercorp |
last post by:
I am debugging an app which blocks many processes in a SQL7 server DB.
The app log writes every transaction "open" and "close".
The weird thing is : when the app logfile says the transaction is
dropped (object closed) the db keeps showing the process "running", in
a sleeping mode, with open_tran in 2 or even 3 and in an awaiting
command...
|
by: Ivan |
last post by:
Hi I am new in DB2, and I have some problems when I try run stored
procedures, and others statements. I made one stored procedure very
simple, but this show different messages.
I have followed the indications that have said me in answer to topics,
but without positive results
This is the stored procedure
CREATE PROCEDURE TESTS ( )
| |
by: nishi57 |
last post by:
I hope I can get some help regarding this issue, which has been going
on for a while. I have a desktop user who is having problem running
"Stored Procedures". The DB2 Connect application works fine but when he
runs the stored procedure, he gets the following error message.
"SYSPROC".CSGCSB54 - Run started.
Data returned in result sets is...
|
by: Ben |
last post by:
Hi!
I already sent this to the ACCESS newsgroup. But since I do not know really
which side is really causing the problem, I have decided to send this
inquiry
to this newsgroup also, if I may.
Below is the environment of the application:
a. MS Access 2003 application running on Windows XP
b. SQL Server 2000 - backend running MS Server...
|
by: db2learner |
last post by:
Hi,
I am new to DB2 and i just started worked on it a couple of days back. I have created basic EMPLOYEE table from control centre which has 2 fields: EmpNo, EmpName.
I am trying to write a simple stored proc in db2 command editor to insert values into these fields.
CREATE PROCEDURE EMP_PROC()
LANGUAGE SQL
BEGIN
INSERT INTO...
|
by: David Greenberg |
last post by:
Hi
We're using SqlServer 2000.
I want to run a DTS using the DTSRUN command.
The commmand is inside a ".bat" file which my application is running
from an SQL client.
No matter how I run it from the client it fails giving me the message:
SQL Server does not exist or access denied
|
by: enggwaqas |
last post by:
I have an Oracle stored procedure that takes approx 3 minutes to execute and I am using .net 2.0 data access provider for oracle. Now i want to cancel the execution of stored procedure from .net after few seconds, the code i wrote for this is:
//Start main function
System.Data.OracleClient.OracleDataAdapter objAdapter;...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |