A couple of things:
1. Switch to using a parameterized query for the SQL to avoid the risk of SQL injection issues:
private void addbtn_Click(object sender, EventArgs e)
{
string connectionstring = @"Data Source=.;Initial Catalog=SuperM;Integrated Security=True";
SqlConnection sqlcon = new SqlConnection(connectionstring);
sqlcon.Open();
SqlCommand cm = new SqlCommand("Select ID, Item_Code, quantity, price from stock where item_code = @ICode", sqlcon);
SqlParameter param = cm.Parameters.Add("@ICode", SqlDbType.NVarChar);
param.Value = itemcodetxt.Text;
SqlDataReader reader = cm.ExecuteReader();
2. As others have said, you cannot multiply strings. This also brings the question of what are the data types in the DB? I'm going to
assume that the price column has a numeric data type like Integer, Single, Double, Currency.
int quantity;
if (!int.TryParse(quantitytxt.Text, out quantity))
{
}
while (reader.Read())
{
var item = new ListViewItem();
item.Text = reader["ID"].ToString();
item.SubItems.Add(reader["item_code"].ToString());
item.SubItems.Add(quantitytxt.Text);
decimal price = Convert.ToDecimal(reader["price"]);
item.SubItems.Add(price.ToString());
item.SubItems.Add((quantity * price).ToString());
listView1.Items.Add(item);
}
The above code has not been tried...