0
在嘗試導出列表中的選定項目時,我已經到了可以知道某個項目在列表中的位置,但我無法獲取文本在該項目位置變量。將選定項目導出到SQL數據庫
if (CustomerListbox.SelectedIndex > -1)
{
for (int i = 0; i < CustomerListbox.GetSelectedIndices().Count(); i++)
{
SqlConnection sqlConn = Connection.GetConnection();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlConn;
{
ListItem li = new ListItem();
li.Value = Convert.ToString(CustomerListbox.GetSelectedIndices().GetValue(i)); //Determines position within listbox
li.Text = Convert.ToString(CustomerListbox.Items.FindByValue(li.Value));
//^^^some magic line of code to do li.text = [email protected]
sqlCmd.CommandText = "ExportCustomers";
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("myquery", "insert into CustomerSelect(Customers) values('" + li.Text + "')");
}
try
{
sqlConn.Open();
sqlCmd.ExecuteNonQuery();
}
catch (Exception e2)
{
throw e2;
}
sqlConn.Close();
}
}
你是我的英雄先生,千恩萬謝。 – sgl