برای update کد زیر رو نوشتم ولی اگر به فیلدهای که convert میشوند به int مقداری ندهم و بعد کلید update رو بزنم روی اولین خطی که این تبدیل قراره انجام بشه پیغام خطای Input string was not in a correct format. رو میدهد این در حالی است که در بانک اجازه null را دادم لطفا راهنماییم کنید چه کنم.اگر نمونه کد گذاشتید ممنون میشم
private void btnUpdate_Click(object sender, EventArgs e)
{
int intposition;
SqlCommand objCommand = new SqlCommand();
intposition = objCurrencyManager.Position;
objCommand.Connection = objConnection;
objCommand.CommandText = "update tbuy set code=@code,name=@name," +
"model=@model,manufacturer=@manufacturer,sn=@s n," +
"country=@country,price=@price,count=@count," +
"date=@date,description=@description where code=@code";
objCommand.CommandType = CommandType.Text;
objCommand.Parameters.AddWithValue("@code",
Convert.ToInt32(txtCode.Text));
objCommand.Parameters.AddWithValue("@name", txtName.Text);
objCommand.Parameters.AddWithValue("@model", txtModel.Text);
objCommand.Parameters.AddWithValue("@manufacturer" ,
txtManufacturer.Text);
objCommand.Parameters.AddWithValue("@sn",
Convert.ToInt32(txtSN.Text));
objCommand.Parameters.AddWithValue("@country", txtCountry.Text);
objCommand.Parameters.AddWithValue("@price",
Convert.ToDecimal(txtPrice.Text));
objCommand.Parameters.AddWithValue("@count",
Convert.ToInt32(txtCount.Text));
objCommand.Parameters.AddWithValue("@date", txtDate.Text);
objCommand.Parameters.AddWithValue("@description",
txtDescription.Text);
objConnection.Open();
objCommand.ExecuteNonQuery();
objConnection.Close();
FillDataSetAndView();
BindFields();
objCurrencyManager.Position = intposition;
ShowPosition();
toolStripStatusLabel1.Text = "Record Updated";
}// end btnUpdate_Click