本文介绍了输入的字符串格式不正确.从组合框过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我试图根据组合框中的选定筛选条件进行过滤,现在每次运行应用程序输入字符串的格式不正确"时,都会出现此错误.
以下是我的客户表格
Hi Guys,Im trying to filter acording to the selected velue from the combobox, now i get this error every time I run my application "Input string was not in a correct format."
Below is my Client form
public partial class Form1 : Form
{
public ProductsBL productBL;
public ArrayList prodList;
ArrayList list;
public Form1()
{
InitializeComponent();
productBL = new ProductsBL();
prodList = new ArrayList();
prodList = productBL.getProducts();
dataGridView1.DataSource = prodList;
dataGridView1.Columns[0].Visible = false;
prodList = productBL.loadComboboxProductID();
comboBox1.DataSource = prodList;
//prodList = new ArrayList();
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Products products = productBL.getSpecificProducts(Convert.ToInt32
(comboBox1.SelectedValue));
dataGridView1.DataSource = products;
}
Below is my Business Layer
public Products getSpecificProducts(int productID)
{
using (SqlConnection con = new SqlConnection(ConnectionString))
{
SqlCommand cmd = new SqlCommand("procGetSingleRowOnProducts", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@productID", SqlDbType.Int));
cmd.Parameters["@productID"].Value = productID;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
Products products = new Products(Convert.ToInt32(reader["ProductID"]), Convert.ToString(reader["productName"]), Convert.ToInt32(reader["supplierID"]), Convert.ToInt32(reader["categoryID"]), Convert.ToString(reader["quantityPerUnit"]), Convert.ToDouble(reader["unitPrice"]), Convert.ToInt16(reader["UnitsInStock"]), Convert.ToInt16(reader["UnitsOnOrder"]), Convert.ToInt16(reader["ReorderLevel"]), Convert.ToBoolean(reader["Discontinued"]));
return products;
}//End
}
推荐答案
Products products = productBL.getSpecificProducts(Convert.ToInt32(comboBox1.SelectedItem));
这篇关于输入的字符串格式不正确.从组合框过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!