问题描述
html代码:<tableborder="0"cellpadding="0"cellspacing="0"style="background-color:#edf6ff;font-size:9pt;height:309px;width:736px;"><tr><tdalign="center"style="height:24px;"colspan="2"><asp:LabelID="Label1"runat="server"Text="餐品新增"SkinID="font_XXLarge"></asp:Label></td></tr><tr><tdalign="left"class="style6">请选择餐品类型:<asp:DropDownListID="DropDownList_goodsType"runat="server"Width="74px"><asp:ListItemValue="1">菜肴</asp:ListItem><asp:ListItemValue="2">汤水</asp:ListItem><asp:ListItemValue="3">点心</asp:ListItem><asp:ListItemValue="4">酒水</asp:ListItem><asp:ListItemValue="5">水果</asp:ListItem></asp:DropDownList></td><tdalign="left"class="style1">餐品名称:<asp:TextBoxID="txt_goodsname"runat="server"></asp:TextBox></td></tr><tr><tdalign="left"class="style6"><asp:LabelID="Label4"runat="server"Text="价格:"></asp:Label><asp:TextBoxID="txt_price"runat="server"></asp:TextBox></td><tdalign="left"class="style1"><asp:LabelID="Label5"runat="server"Text="类型编号:"></asp:Label><asp:TextBoxID="txt_typeid"runat="server"></asp:TextBox></td></tr><tr><tdalign="left"class="style6"><asp:LabelID="Label6"runat="server"Text="主料:"></asp:Label><asp:TextBoxID="txt_main"runat="server"></asp:TextBox></td><tdalign="left"class="style1"><asp:LabelID="Label7"runat="server"Text="数量:"></asp:Label><asp:TextBoxID="number"runat="server"Width="115px"></asp:TextBox></td></tr><tr><tdalign="left"class="style6"><asp:LabelID="Label8"runat="server"Text="口感:"></asp:Label><asp:TextBoxID="txt_taste"runat="server"></asp:TextBox></td><tdalign="left"class="style1"> </td></tr><tr><tdalign="left"class="style4"><asp:LabelID="Label12"runat="server"Text="图片:"></asp:Label><asp:FileUploadID="FileUpload_Image"runat="server"Height="19px"Width="216px"/></td><tdalign="left"class="style5"> </td></tr><tr><tdalign="center"colspan="2"class="style2"><asp:ButtonID="btn_Ok"runat="server"Text="添加"OnClick="btn_Ok_Click"/></td></tr></table>cs代码:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;publicpartialclassadmin_add:System.Web.UI.Page{StringSqlStr;DBdb=newDB();DataSetDs=newDataSet();Stringfull_name;voidGoodsType_DataBind(){SqlStr="select*fromgoodsType";Ds=db.GetDataTableBySql(SqlStr);try{stringgoodstype_name;for(inti=0;i<Ds.Tables[0].Rows.Count;i++){goodstype_name=Ds.Tables[0].Rows[i][1].ToString();DropDownList_goodsType.Items.Add(goodstype_name);}}catch(Exception){Response.Write("<script>alert('没有获得数据!')</script>");}}protectedvoidPage_Load(objectsender,EventArgse){if(Page.IsPostBack==false){//Session["Username"]="admin";if(Session["Admin_UserName"]!=null){GoodsType_DataBind();}else{Response.Write("<scripe>alert('error')</script>");}}}protectedvoidbtn_Ok_Click(objectsender,EventArgse){if(Session["Admin_UserName"]!=null){try{stringpath_file=FileUpload_Image.PostedFile.FileName.ToString();stringfile_type=path_file.Substring(path_file.LastIndexOf("."));stringfile_name=DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString();full_name=file_name+file_type;stringpath=Server.MapPath("../images\")+full_name;FileUpload_Image.SaveAs(path);}catch(Exception){Response.Write("<script>alert('上传文件失败!')</script>");}SqlStr="select*fromgoodsTypewheretypename='"+DropDownList_goodsType.Text.Trim()+"'";Ds=db.GetDataTableBySql(SqlStr);//stringtype_id=Ds.Tables[0].Rows[0][0].ToString();stringimage_path="../images\"+full_name;SqlStr="insertintogoodsInfo(goods_name,price,type_id,main_ingredients,number,taste,type_name,img)"+"values('"+this.txt_goodsname.Text+"','"+this.txt_price.Text+"','"+this.txt_typeid+"',"+"'"+this.txt_main+"','"+this.number.Text+"',"+"'"+this.txt_taste.Text+"','"+this.DropDownList_goodsType.Text+"',"+"'"+image_path+"')";//Response.Write(SqlStr);try{if(db.UpdateDataBySql(SqlStr)){Response.Write("<script>alert('餐品新增成功!')</script>");}else{Response.Write("<script>alert('餐品新增失败!')</script>");}}catch(Exception){Response.Write("<script>alert('餐品新增失败')</script>");}}else{Response.Write("<script>alert('error')</script>");}}}求大神们帮帮忙,感激万分!
解决方案
解决方案二:
贴下报错信息
解决方案三:
调试一下看看报错信息