1

My application needs to get data from a store procedure. In a query program the stored procedure works fine;

exec MyStoredProdure @Prama1 = '01'

In WPF it times out. Here is my code;

using (SqlConnection con = new SqlConnection(ConString))
{
    con.Open();
    SqlCommand cmd = new SqlCommand();
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@Prama1", "01");
    cmd.CommandText = "MyStoredProdure";
    cmd.Connection = con;
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable("MyStoredProdure");
    sda.Fill(dt);

    foreach (DataRow dr in dt.Rows)
    {
       //Do code
    }
    con.Close();
}

It is timing out right on sda.Fill(dt). It should be noted that Select and inserts work perfectly fine.

1 Answers1

0

I believe you're missing the sda.SelectCommand = cmd; before the fill. How to use a DataAdapter with stored procedure and parameter

Community
  • 1
  • 1
sjramsay
  • 555
  • 1
  • 5
  • 12