我的朋友们,这些代码有什么问题,出现“输入字符串的格式不正确”。错误 ?????????
它出现在以 * 开头的行中,谁能帮助我?
try
{
using (SqlConnection con = new SqlConnection(connect))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO fact_info(fact_id, druge,price,amount,total,selldate) VALUES (@C1, @C2, @C3, @C4, @C5 ,@C6)", con))
{
cmd.Parameters.Add(new SqlParameter("@C1", SqlDbType.Int ));
cmd.Parameters.Add(new SqlParameter("@C2", SqlDbType.NVarChar));
cmd.Parameters.Add(new SqlParameter("@C3", SqlDbType.Int));
cmd.Parameters.Add(new SqlParameter("@C4", SqlDbType.Int));
cmd.Parameters.Add(new SqlParameter("@C5", SqlDbType.Int));
cmd.Parameters.Add(new SqlParameter("@C6", SqlDbType.NVarChar ));
con.Open();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (!row.IsNewRow)
{
*****cmd.Parameters["@C1"].Value =Convert .ToInt32 ( label3.Text.Trim());
cmd.Parameters["@C2"].Value = row.Cells[1].Value.ToString ();*****
cmd.Parameters["@C3"].Value =Convert .ToInt32 ( row.Cells[2].Value.ToString ());
cmd.Parameters["@C4"].Value =Convert .ToInt32 ( row.Cells[3].Value.ToString ());
cmd.Parameters["@C5"].Value =Convert .ToInt32 ( row.Cells[4].Value.ToString ());
cmd.Parameters["@C6"].Value = label5.Text.Trim();
cmd.ExecuteNonQuery();
}
}
}
}
}
finally
{
MessageBox.Show("done! ");
}
}