我该如何解决这个问题 [英] How do I solve this ob
本文介绍了我该如何解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我点击提交按钮时会发生这种情况
This is what happens when I click submit button
if (btn_add.Text == "Submit")
{
string BracketSuspensionType = Convert.ToString(txt_BracketSuspensionType.Text.Trim());
string PoleTypeID = Convert.ToString(dd_PoleTypeID.SelectedValue.Trim());
string Status = chk_Active.Checked ? "True" :"False" ;
System.Collections.Hashtable ht = (System.Collections.Hashtable)Session["UserDetails"];
Int64 UsrId = (Int64)ht["UserID"];
string CreatedBy = UsrId.ToString();
//string CreatedOn = (DateTime.Now);
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
fileuploadimages.SaveAs(Server.MapPath("~/Images/" + filename));
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["valmont"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("Insert into DEF_BRACKET_ACCESSORIES_MST(BracketSuspensionType,PoleTypeID,Status,CreatedBy,CreatedOn,ImagePath) values(@BracketSuspensionType,@PoleTypeID,Status,@CreatedBy,@CreatedOn,@ImagePath)", con);
cmd.Parameters.AddWithValue("@BracketSuspensionType", BracketSuspensionType);
cmd.Parameters.AddWithValue("@PoleTypeID", PoleTypeID);
cmd.Parameters.AddWithValue("@Status", Status);
cmd.Parameters.AddWithValue("@CreatedBy", CreatedBy);
//cmd.Parameters.AddWithValue("@CreatedOn", CreatedOn);
cmd.Parameters.AddWithValue("@ImagePath", "Images/" + filename);
cmd.ExecuteNonQuery();
con.Close();
错误 - App_Web_vbsffejd.dll中出现System.NullReferenceException类型的异常,但未在用户代码中处理
附加信息:对象引用未设置为对象的实例。
错误在线 -
Error - An exception of type 'System.NullReferenceException' occurred in App_Web_vbsffejd.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
Error on Line-
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
请建议
Please suggest
推荐答案
你的fileuploadimages .PostedFile返回似乎是空的?检查一下。
what your "fileuploadimages.PostedFile" returns seems its null? Check it.
检查是否有要保存在数据库中的文件
check whether you have file to save in database
if (btn_add.Text == "Submit" && fileuploadimages.PostedFile !=null)
这篇关于我该如何解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文