本文介绍了显示错误的连接属性未初始化.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我执行时,此代码显示错误"executenonquery-connection属性未初始化"
有人可以帮我吗?
when i am executing, this code is showing error "executenonquery-connection property is not initialized"
can anyone help me?
public void connect()
{
SqlConnection con = new SqlConnection(@"Data Source=CSZ-PCS43132\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True");
con.Open();
}
public string viewdetails(HRViewpagedetailsMDL objEditListingPage)
{
connect();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_USERPROFILE_INSERT";
cmd.Parameters.AddWithValue("@firstname",objEditListingPage.firstName);
cmd.Parameters.AddWithValue("@lastname", objEditListingPage .lastname);
cmd.Parameters.AddWithValue("@email", objEditListingPage .email);
cmd.Parameters.AddWithValue("@newrecruit",objEditListingPage .newrecruit);
cmd.Parameters.AddWithValue("@siteid", objEditListingPage.site.siteid);
cmd.Parameters.AddWithValue("@comments", objEditListingPage.comments);
cmd.Parameters.AddWithValue("@manageothers", objEditListingPage.manageothers);
cmd.Parameters.AddWithValue("@topfunctionid", objEditListingPage.topfunction.topfunctionid);
cmd.Parameters.AddWithValue("@subfunctionid", objEditListingPage.subfunction.subfunctionid);
cmd.Parameters.AddWithValue("@lmsroleid", objEditListingPage.lmsrole.lmsroleid);
cmd.Parameters.AddWithValue("@channelid", objEditListingPage.channel.channelid);
cmd.Parameters.AddWithValue("@employmentstatusid", objEditListingPage.employmentstatus.employmentstatusid);
cmd.Parameters.AddWithValue("@statusid", objEditListingPage.status.statusid);
cmd.Parameters.AddWithValue("@active", objEditListingPage.active);
cmd.Parameters.AddWithValue("@audiencefunctionallmsid", objEditListingPage.audiencefunctionallms);
cmd.Parameters.AddWithValue("@audiencelmsspecial", objEditListingPage.audiencespeciallms);
cmd.Parameters.AddWithValue("@existingthecompany", objEditListingPage.existingthecompany);
cmd.Parameters.AddWithValue("@localjobtitle", objEditListingPage.localjobtitle);
cmd.Parameters.AddWithValue("@locallanguagejobtitle", objEditListingPage.locallanguagejobtitle);
cmd.Parameters.AddWithValue("@kmlevel", objEditListingPage.kmlevel);
return cmd.ExecuteNonQuery().ToString();
}
推荐答案
SqlConnection con;
public void connect()
{
con = new SqlConnection(@"Data Source=CSZ-PCS43132\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True");
}
public string viewdetails(HRViewpagedetailsMDL objEditListingPage)
{
connect();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_USERPROFILE_INSERT";
cmd.Parameters.AddWithValue("@firstname",objEditListingPage.firstName);
cmd.Parameters.AddWithValue("@lastname", objEditListingPage .lastname);
cmd.Parameters.AddWithValue("@email", objEditListingPage .email);
cmd.Parameters.AddWithValue("@newrecruit",objEditListingPage .newrecruit);
cmd.Parameters.AddWithValue("@siteid", objEditListingPage.site.siteid);
cmd.Parameters.AddWithValue("@comments", objEditListingPage.comments);
cmd.Parameters.AddWithValue("@manageothers", objEditListingPage.manageothers);
cmd.Parameters.AddWithValue("@topfunctionid", objEditListingPage.topfunction.topfunctionid);
cmd.Parameters.AddWithValue("@subfunctionid", objEditListingPage.subfunction.subfunctionid);
cmd.Parameters.AddWithValue("@lmsroleid", objEditListingPage.lmsrole.lmsroleid);
cmd.Parameters.AddWithValue("@channelid", objEditListingPage.channel.channelid);
cmd.Parameters.AddWithValue("@employmentstatusid", objEditListingPage.employmentstatus.employmentstatusid);
cmd.Parameters.AddWithValue("@statusid", objEditListingPage.status.statusid);
cmd.Parameters.AddWithValue("@active", objEditListingPage.active);
cmd.Parameters.AddWithValue("@audiencefunctionallmsid", objEditListingPage.audiencefunctionallms);
cmd.Parameters.AddWithValue("@audiencelmsspecial", objEditListingPage.audiencespeciallms);
cmd.Parameters.AddWithValue("@existingthecompany", objEditListingPage.existingthecompany);
cmd.Parameters.AddWithValue("@localjobtitle", objEditListingPage.localjobtitle);
cmd.Parameters.AddWithValue("@locallanguagejobtitle", objEditListingPage.locallanguagejobtitle);
cmd.Parameters.AddWithValue("@kmlevel", objEditListingPage.kmlevel);
con.Open();
string result= cmd.ExecuteNonQuery().ToString();
con.Close();
return result;
}
这篇关于显示错误的连接属性未初始化.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!