PDA

View Full Version : Failed to convert parameter value from string to decimal



dare_khamosh
پنج شنبه 08 اسفند 1387, 01:40 صبح
وقتی برنامه رو اجرا می کنم با این پیغام مواجه می شم
Failed to convert parameter value from a String to a Decimal.

اینم کد:
int intPosition, intMaxID;
String strID;
SqlCommand objCommand = new SqlCommand();
intPosition = objCurrencyManager.Position;
SqlCommand maxIdCommand = new SqlCommand("SELECT MAX(au_id) FROM authors WHERE au_id LIKE '999-88-'", objConnection);
objConnection.Open();
Object maxId = maxIdCommand.ExecuteScalar();
if (maxId == DBNull.Value)
{
intMaxID = 1000;
}
else
{
strID = (String)maxId;
intMaxID = int.Parse(strID.Remove(0, 7));
intMaxID += 1;
}
strID = "999-88-" + intMaxID.ToString();
objCommand.Connection = objConnection;
objCommand.CommandText =
"INSERT INTO authors (au_id, au_lname, au_fname, phone, address) " +
"VALUES(@au_id,@au_lname,@au_fname,@phone,@address)";
objCommand.Parameters.AddWithValue("@au_id", strID);
objCommand.Parameters.AddWithValue("au_lname", txtLastName.Text);
objCommand.Parameters.AddWithValue("au_fname", txtFirstName.Text);
objCommand.Parameters.AddWithValue("@phone", txtPhone.Text).DbType = DbType.Currency;
objCommand.Parameters.AddWithValue("@address", txtAddress.Text);
try
{
objCommand.ExecuteNonQuery();
}
catch (SqlException SqlExceptionErr)
{
MessageBox.Show(SqlExceptionErr.Message);
}
objConnection.Close();

majid325
پنج شنبه 08 اسفند 1387, 06:05 صبح
try و catch رو بردار ببین رو کدوم خط error میده , زمان تبدیل داده از casting استفاده کن.