form close

H

Hrcko

int active = 0;

conn = new SqlConnection (sConn);
conn.Open() ;
SqlCommand sc = new SqlCommand ("LogoActiveCheck",conn);
sc.CommandType = CommandType.StoredProcedure;
sc.Parameters.Add (
new SqlParameter ("@RowCount",ParameterDirection.ReturnValue));
sc.ExecuteNonQuery();
sc.Connection.Close ();
active = (int)sc.Parameters["@RowCount"].Value;


I'm using this code to get @rowcount, but when it finishes form closes.
Why?

Hrcko
 
R

Richard Blewett [DevelopMentor]

Hrcko said:
int active = 0;

conn = new SqlConnection (sConn);
conn.Open() ;
SqlCommand sc = new SqlCommand ("LogoActiveCheck",conn);
sc.CommandType = CommandType.StoredProcedure;
sc.Parameters.Add (
new SqlParameter ("@RowCount",ParameterDirection.ReturnValue));
sc.ExecuteNonQuery();
sc.Connection.Close ();
active = (int)sc.Parameters["@RowCount"].Value;

I'm using this code to get @rowcount, but when it finishes form closes.
Why?

Hrcko

You need to keep the connection open until you have read the parameter. You
are getting an exception which is ending up terminating the app
Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
 
H

Hrcko

I put a variable active after ExecuteNonQuery, but it closes when
Execute NonQuery is finished.

Hrcko
int active = 0;

conn = new SqlConnection (sConn);
conn.Open() ;
SqlCommand sc = new SqlCommand ("LogoActiveCheck",conn);
sc.CommandType = CommandType.StoredProcedure;
sc.Parameters.Add (
new SqlParameter ("@RowCount",ParameterDirection.ReturnValue));
sc.ExecuteNonQuery();
sc.Connection.Close ();
active = (int)sc.Parameters["@RowCount"].Value;

I'm using this code to get @rowcount, but when it finishes form closes.
Why?

Hrcko


You need to keep the connection open until you have read the parameter. You
are getting an exception which is ending up terminating the app
Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Where this piece of code is located?

Are you getting any exception?

Set the debugger to "break on exception" to see if you are getting some
exception


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Hrcko said:
I put a variable active after ExecuteNonQuery, but it closes when Execute
NonQuery is finished.

Hrcko
int active = 0;

conn = new SqlConnection (sConn);
conn.Open() ;
SqlCommand sc = new SqlCommand ("LogoActiveCheck",conn);
sc.CommandType = CommandType.StoredProcedure;
sc.Parameters.Add (
new SqlParameter ("@RowCount",ParameterDirection.ReturnValue));
sc.ExecuteNonQuery();
sc.Connection.Close ();
active = (int)sc.Parameters["@RowCount"].Value;

I'm using this code to get @rowcount, but when it finishes form closes.
Why?

Hrcko


You need to keep the connection open until you have read the parameter.
You are getting an exception which is ending up terminating the app
Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top