Nathan

Nathan

  • NA
  • 24
  • 15.5k

Retrieve Data as per the ListView selection in C#

Feb 27 2014 5:34 AM
Sir, I want your help in guiding me to get a function result. Take a look to the following form:-




In this form I want to display textboxes with database value as per the listview selection. The database value are:-



The C# form.cs code I wrote for this is:-

try
            {

                string cnn = ConfigurationManager.ConnectionStrings["MSCon_Pharm"].ToString();
                SqlConnection cn = new SqlConnection(cnn);
                cn.Open();
                SqlCommand cmd = new SqlCommand("GetTaxSlabDetails", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("as_Name", SqlDbType.NVarChar, 50).Value = lstTaxSlab.FocusedItem.ToString();
                SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adpt.Fill(ds);
              
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        txtSlabName.Text = ds.Tables[0].Rows[i]["Name"].ToString();
                          
                    }
            }
            catch (Exception)
            {
               
                throw;
            }

in this, the row become Zero and the loop exists.

Answers (1)