当我运行这段代码我就赶上(例外五)部分得到了一个错误,我不知道为什么,编译器说的“当地命名为“E”变量不能在此范围中声明,因为它会给予不同的意义,“E”,这已经是一个“父母或电流”范围用来表示别的东西”我上“例外”部分的错误,我不知道为什么
try
{
//Form Query which will insert Company and will output generated id
myCommand.CommandText = "Insert into Comp(company_name) Output Inserted.ID VALUES (@company_name)";
myCommand.Parameters.AddWithValue("@company_name", txtCompName);
int companyId = Convert.ToInt32(myCommand.ExecuteScalar());
//For the next scenario, in case you need to execute another command do it before committing the transaction
myTrans.Commit();
//Output Message in message box
MessageBox.Show("Added", "Company Added with id" + companyId, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception e)
{
try
{
myTrans.Rollback();
}
catch (SqlException ex)
{
if (myTrans.Connection != null)
{
MessageBox.Show("An exception of type " + ex.GetType() +
" was encountered while attempting to roll back the transaction.");
}
}
MessageBox.Show("An exception of type " + e.GetType() +
"was encountered while inserting the data.");
MessageBox.Show("Record was written to database.");
}
finally
{
myConnection.Close();
}
希望你的回复!谢谢!
请注意,如果您在MSDN中查找错误代码(如CS0136在你的情况下),你会得到的文章,解释常见的情况,并展示样品 - [编译器错误CS0136(http://msdn.microsoft.com/en-us /library/973aa6bt%28v=vs.90%29.aspx) –