我在if语句中声明了一个对象,surgeonRow: if(addNewSurgeonChkBx.Checked == true) { DataRow surgeonRow = dsAddAssessment.Tables [" Surgeon"] .NewRow(); surgeonRow [" sgnTitle"] = titleCboBx .SelectedValue; surgeonRow [" sgnFName"] = fNameTxtBx.Text; surgeonRow [" sgnLName"] = lNameTxtBx.Text; surgeonRow [" estNo"] =会话[" establishment"]。ToString(); dsAddAssessment.Tables [" Surgeon"]。Rows.Add(surgeonRow); } 但是当我尝试再次使用它时: if(addNewSurgeonChkBx.Checked == true) { assessmentRow.SetParentRow(surgeonRow); } surgeonRow突出显示并且构建错误名称''surgeonRow'' 在类或命名空间中不存在给出了。 有没有办法参考它?我无法移动 DataRow surgeonRow = dsAddAssessment.Tables [" Surgeon"] .NewRow(); 行出if声明克服了这个错误,因为它产生了更多的错误。 谢谢。
解决方案surgeonRow在if中声明声明,因此是该声明的当地 。在if之外声明它阻挡在 的顶部你的方法或班级的顶级。 最好的问候 Johann Blake
我试过这个但是如果我这样做会造成更多问题。我可能需要 来代替克服这些代码。 谢谢
不,你做错了。你不要移动整行,只需要 声明,就像这样... DataRow外科医生现在; if(addNewSurgeonChkBx.Checked == true) { surgeonRow = dsAddAssessment.Tables [" Surgeo * n"] .NewRow(); surgeonRow [" sgnTitle"] = titleCboBx.SelectedValue; surgeonRow [" sgnFName"] = fNameTxtBx.Text; surgeonRow [" sgnLName"] = lNameTxtBx.Text; surgeonRow [" estNo"] =会话[" establishment"]。ToStr * ing(); dsAddAssessment.Tables [" Surgeo * n"]。行。添加(SurgeonRow); } 最好的问候 Johann Blake
Hi, I declare an object, surgeonRow within an if statement: if(addNewSurgeonChkBx.Checked == true) { DataRow surgeonRow = dsAddAssessment.Tables["Surgeon"].NewRow(); surgeonRow["sgnTitle"] = titleCboBx.SelectedValue; surgeonRow["sgnFName"] = fNameTxtBx.Text; surgeonRow["sgnLName"] = lNameTxtBx.Text; surgeonRow["estNo"] = Session["establishment"].ToString(); dsAddAssessment.Tables["Surgeon"].Rows.Add(surgeonRow); } however when i try to use it again like this: if(addNewSurgeonChkBx.Checked == true) { assessmentRow.SetParentRow(surgeonRow); } surgeonRow is highlighted and the build error "The name ''surgeonRow'' does not exist in the class or namespace" is given. is there a way to reference it? I cant move the DataRow surgeonRow = dsAddAssessment.Tables["Surgeon"].NewRow(); line out of the if statement to overcome this error, as it produces more errors. Thanks.
解决方案 surgeonRow is declared inside an "if" statement and therefore is local to that statement. Declare it outside of the "if" block at the top of your method or the top of your class. Best Regards Johann Blake I have tried this but it creates many more problems if i do. i may have to play around the the code to overcome those instead. Thanks No you''re doing it wrong. You don''t move the entire line, just the declaration, like this... DataRow surgeonRow; if(addNewSurgeonChkBx.Checked == true) { surgeonRow = dsAddAssessment.Tables["Surgeo*n"].NewRow(); surgeonRow["sgnTitle"] = titleCboBx.SelectedValue; surgeonRow["sgnFName"] = fNameTxtBx.Text; surgeonRow["sgnLName"] = lNameTxtBx.Text; surgeonRow["estNo"] = Session["establishment"].ToStr*ing(); dsAddAssessment.Tables["Surgeo*n"].Rows.Add(surgeonRow); } Best Regards Johann Blake更多推荐
在类或命名空间中不存在?
发布评论