Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi every body,

I have that code:

When i run my web project there are three different messages appear,
every message appear in one time.

When i make run, message error appear for that code:
C#
public static int GetNumOfTopicInTable(out int TopicsNum)
    {
        topicCommand.Connection = connection;

        topicCommand.CommandType = CommandType.StoredProcedure;
        topicCommand.CommandText = "uspNumOfTopicInTable";

        connection.Open();
        TopicsNum = Convert.ToInt32(topicCommand.ExecuteScalar());
        connection.Close();

        return TopicsNum;
    }


when the caller reach to that line of:
MIDL
connection.Open();

this error appear:
The connection was not closed. The connection's current state is open.
Although it is first time i open it.

But when i close VS 2005 and open it again and make run this message appear:
There is no row at position 9.

for that code:

lbtnHomeTopicAddress.Text = topicDataSet.Tables[0].Rows[i]["TopicAddress"].ToString();


And when i try to run project by press on F11 this another message appear:
Procedure uspNumOfTopicInTable has no parameters and arguments were supplied.

for that code:
TopicsNum = Convert.ToInt32(topicCommand.ExecuteScalar());

any one can help me please

OP solved the issue himself & question masked as Solved
Posted
Updated 12-Nov-10 20:11pm
v9

Just to remove it from the unanswered list. Might be someone face something similar in future and then this question(OP actually) might help.

To OP: Please do update the question with answer for others - it would help in future to reference.
 
Share this answer
 
Comments
MrLonely_2 22-Nov-10 13:39pm    
ok

i did it

thank you
I found the solution for my problems and it is that:

first problem:

The connection was not closed. The connection's current state is open.

solution:

I used try....catch...finally:

C#
try
{
   connection.Open();
   TopicsNum = Convert.ToInt32(topicCommand.ExecuteScalar());
   connection.Close();
}
catch
{

}
finally
{
   connection.close();
}



second problem:

Procedure uspNumOfTopicInTable has no parameters and arguments were supplied.


solution:

I used this code:

MIDL
topicCommand.Parameters.clear();



the last problem is custom problem that related to my code and i solved it according to my case.


Thanks every body
bye
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900