troubleshooting Question

Try, Catch

Avatar of metta0_3
metta0_3 asked on
Microsoft SQL ServerC#ASP.NET
5 Comments1 Solution266 ViewsLast Modified:
I have this simple connection to database. I need a try, catch in case of a failed connection. Can anyone assist in placing it in. I cannot get it to work.

protected void GetVendorsInfo_SelectedIndexChanged(object sender, EventArgs e)
    {
        string myString = drpInputVendor.SelectedValue;
        ClearControls();

       
        if (myString != "Select A Vendor")
        {
            SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("SelectedVendor", conn);

            SqlParameter inputParam1 = new SqlParameter("@myVendCode", SqlDbType.VarChar, 15);
            inputParam1.Value = drpInputVendor.SelectedValue;
           
            SqlParameter inputParam2 = new SqlParameter("@myItemNo", SqlDbType.VarChar, 15);
            inputParam2.Value = txtInputItemCode.Text;

            SqlParameter outputParam = new SqlParameter("@result", SqlDbType.VarChar, 15);
            outputParam.Direction = ParameterDirection.Output;
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(inputParam1);
            cmd.Parameters.Add(inputParam2);
            cmd.Parameters.Add(outputParam);

            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            dataAdapter.Fill(ds);

            DataTable dt = ds.Tables[0];            

            foreach (DataRow dr in dt.Rows)
            {
                txtInputVendorPartNo.Text = dr.ItemArray[0].ToString();

                txtInputBoxQty.Text = dr.ItemArray[1].ToString();
                txtInputBoxQty.Text = txtInputBoxQty.Text.Split('.')[0];
            }

            conn.Close();
        }
        RetrieveRemainder();
    }

Regards...
ASKER CERTIFIED SOLUTION
Dhanasekaran Sengodan

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros