0

hey,
does anyone know how to handle this exception?

please help me

//Retrieves all the contract numbers from the Contract table
        public String[] getPhaseNumbers(String TopicNo)
        {
            db.openConnection();

            String query = @"Select Phase From Topic Where TopicNo = @topicNo";
            SqlCommand command = new SqlCommand(query, DB.getConnection());

            command.Parameters.Add("@topicNo",SqlDbType.Int).Value = TopicNo;

            SqlDataAdapter da = new SqlDataAdapter(command);
            DataTable dt = new DataTable();

[B]            da.Fill(dt);
[/B]
            int NoOfRows = dt.Rows.Count;
            String[] phase = new String[NoOfRows];


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                phase[i] = dt.Rows[i]["Phase"].ToString();

            }

            db.closeConnection();

            return phase;

        }

from the place the code is bolded it says "Failed to convert parameter value from a String to a Int32."

why is this
w@ is the solution for this ?

please give me an answer?
thankxxxxxxxxxx

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Ionelul
0

change

command.Parameters.Add("@topicNo",SqlDbType.Int).Value = TopicNo;

with

command.Parameters.Add("@topicNo",SqlDbType.Int).Value = Int32.Parse(TopicNo);

Hope this helps.

Ionut

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.