本文介绍了需要帮助将参数传递给ExecuteScalar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Hello all 我收到一条错误消息:对象引用未设置为对象的实例。行旁边:有人可以帮我修复此错误 var orderExists =( Int32 )ChkavailbleJobCMD.ExecuteScalar()> 0 ; protected void LinkButton4_Click( object sender,EventArgs e) { JobsMView.ActiveViewIndex = 2 ; 使用( var UsOrderCon = new SqlConnection(cs)) { UsOrderCon.Open(); string chksBervJobsSt = 选择JobNum,Jobtitle,Dept,VacCountry,Employer from Employer = @ Emp; SqlCommand ChkavailbleJobCMD = new SqlCommand(chksBervJobsSt,UsOrderCon); ChkavailbleJobCMD.Parameters.AddWithValue( @Emp, Berava); var orderExists =( Int32 )ChkavailbleJobCMD.ExecuteScalar()> 0 ; if (orderExists) { jobsAvaPan.Visible = 真; SqlDataAdapter BervJonavaADPA = new SqlDataAdapter( SELECT JobNum,Jobtitle,Dept,VacCountry,Employer FROM jobs WHERE Employer = @Emp,cs); BervJonavaADPA.SelectCommand.Parameters.AddWithValue( @Emp, Berava); DataSet BervJonavaDST = new DataSet(); BervJonavaADPA.Fill(BervJonavaDST); GridView1.DataSource = BervJonavaDST.Tables [ 0 ]; GridView1.DataBind(); } else { NoJobAvPan.Visible = 真; NoJobLbl.Text = 抱歉,我们目前没有任何工作可用; } } } 解决方案 更改 选择 JobNum,Jobtitle,Dept,VacCountry,雇主来自的工作其中雇主= @Emp to 选择 count(*)来自作业其中雇主= @ EMP Hello allI am getting an error message: " Object reference not set to an instance of an object. " next to line: so can someone help me to fix this errorvar orderExists = (Int32)ChkavailbleJobCMD.ExecuteScalar() > 0;protected void LinkButton4_Click(object sender, EventArgs e) { JobsMView.ActiveViewIndex = 2; using (var UsOrderCon = new SqlConnection(cs)) { UsOrderCon.Open(); string chksBervJobsSt = "Select JobNum, Jobtitle, Dept, VacCountry, Employer from jobs where Employer=@Emp"; SqlCommand ChkavailbleJobCMD = new SqlCommand(chksBervJobsSt, UsOrderCon); ChkavailbleJobCMD.Parameters.AddWithValue("@Emp", "Berava"); var orderExists = (Int32)ChkavailbleJobCMD.ExecuteScalar() > 0; if (orderExists) { jobsAvaPan.Visible = true; SqlDataAdapter BervJonavaADPA = new SqlDataAdapter("SELECT JobNum, Jobtitle, Dept, VacCountry, Employer FROM jobs WHERE Employer = @Emp ", cs); BervJonavaADPA.SelectCommand.Parameters.AddWithValue("@Emp", "Berava"); DataSet BervJonavaDST = new DataSet(); BervJonavaADPA.Fill(BervJonavaDST); GridView1.DataSource = BervJonavaDST.Tables[0]; GridView1.DataBind(); } else { NoJobAvPan.Visible = true; NoJobLbl.Text = "Sorry, we don't have any job available at the moment"; } } } 解决方案 changeSelect JobNum, Jobtitle, Dept, VacCountry, Employer from jobs where Employer=@EmptoSelect count(*) from jobs where Employer=@Emp 这篇关于需要帮助将参数传递给ExecuteScalar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 08:21