asp.net 表单如何将数据提交到数据库中
我是.net初学者有很多的不明白之处,希望有能力的大侠们帮帮小弟。谁能给做个实例啊?我用的是vb.net!能把输入表单的内容传递到数据库中就行了!...
我是.net初学者有很多的不明白之处,希望有能力的大侠们帮帮小弟。
谁能给做个实例啊?我用的是vb.net!能把输入表单的内容传递到数据库中就行了! 展开
谁能给做个实例啊?我用的是vb.net!能把输入表单的内容传递到数据库中就行了! 展开
展开全部
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" id="TABLE1" >
<tr>
<td width="18%" align="center" bgcolor="#FFFFFF" class="F">设置名称</td>
<td width="61%" height="25" align="center" bgcolor="#FFFFFF" class="F">基本参数设置</td>
<td width="21%" align="center" bgcolor="#FFFFFF" class="F">设置说明</td>
</tr>
<tr>
<td align="center" bgcolor="#F6F6F6">
分类名称:</td>
<td height="25" align="left" bgcolor="#F6F6F6">
<asp:DropDownList ID="ddlProductType" runat="server" Width="184px">
</asp:DropDownList></td>
<td bgcolor="#F6F6F6"> </td>
</tr>
<tr>
<td align="center" bgcolor="#F6F6F6" style="height: 27px">
公告标题:</td>
<td align="left" bgcolor="#F6F6F6" style="height: 27px">
<asp:TextBox ID="tbProductName" runat="server" Width="298px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbProductName"
ErrorMessage="该项不能为空"></asp:RequiredFieldValidator>
</td>
<td bgcolor="#F6F6F6" style="height: 27px"> </td>
</tr>
<tr>
<td align="center" bgcolor="#f6f6f6" style="height: 27px">
上传图片:</td>
<td align="left" bgcolor="#f6f6f6" style="height: 27px">
<asp:TextBox ID="tbPicPath" runat="server"></asp:TextBox>
<asp:FileUpload ID="FileUpload1" runat="server" Height="22px" Width="185px" />
<asp:Button ID="btnUpLoad" runat="server" Text="上传图片" />
<span style="color: #ff0033">如果不需要图片,则不需要上传</span></td>
<td bgcolor="#f6f6f6" style="height: 27px">
</td>
</tr>
<tr>
<td align="center" bgcolor="#f6f6f6" style="height: 27px">
公告详细信息:</td>
<td align="left" bgcolor="#f6f6f6" style="height: 27px">
<CE:Editor ID="Editor1" runat="server">
</CE:Editor>
</td>
<td bgcolor="#f6f6f6" style="height: 27px">
</td>
</tr>
<tr>
<td align="center" bgcolor="#f6f6f6" style="height: 27px">
</td>
<td align="left" bgcolor="#f6f6f6" style="height: 27px">
</td>
<td bgcolor="#f6f6f6" style="height: 27px">
</td>
</tr>
<tr>
<td align="center" bgcolor="#f6f6f6" style="height: 27px">
</td>
<td align="left" bgcolor="#f6f6f6" style="height: 27px">
<asp:Button ID="Button1" runat="server" Text="提 交" Width="104px" OnClick="Button1_Click" /></td>
<td bgcolor="#f6f6f6" style="height: 27px">
</td>
</tr>
</table>
protected void Button1_Click(object sender, EventArgs e)
{
DBNewsDetail news = new DBNewsDetail();
//common.check_str(this.Editor1.Text);
bool bl = news.AddNotice(common.FormatText(this.tbProductName), this.Editor1.Text, this.tbPicPath.Text);
if(bl==true)
{
common.ShowMsg("添加成功!", "NewsList.aspx");
}
else
{}
}
sql语句函数
public bool AddNotice(string Title, string Detail, string picPath)
{
string sql = @"insert into Notice(NoticeTitle,Detail,picPath,AddTime) values('" + Title + "','" + Detail + "','" + picPath + "','"+System.DateTime.Now.Date+"')";
try
{
int i = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql);
if (i > 0)
return true;
else
return false;
}
catch (Exception ex)
{
throw ex;
}
}
<tr>
<td width="18%" align="center" bgcolor="#FFFFFF" class="F">设置名称</td>
<td width="61%" height="25" align="center" bgcolor="#FFFFFF" class="F">基本参数设置</td>
<td width="21%" align="center" bgcolor="#FFFFFF" class="F">设置说明</td>
</tr>
<tr>
<td align="center" bgcolor="#F6F6F6">
分类名称:</td>
<td height="25" align="left" bgcolor="#F6F6F6">
<asp:DropDownList ID="ddlProductType" runat="server" Width="184px">
</asp:DropDownList></td>
<td bgcolor="#F6F6F6"> </td>
</tr>
<tr>
<td align="center" bgcolor="#F6F6F6" style="height: 27px">
公告标题:</td>
<td align="left" bgcolor="#F6F6F6" style="height: 27px">
<asp:TextBox ID="tbProductName" runat="server" Width="298px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbProductName"
ErrorMessage="该项不能为空"></asp:RequiredFieldValidator>
</td>
<td bgcolor="#F6F6F6" style="height: 27px"> </td>
</tr>
<tr>
<td align="center" bgcolor="#f6f6f6" style="height: 27px">
上传图片:</td>
<td align="left" bgcolor="#f6f6f6" style="height: 27px">
<asp:TextBox ID="tbPicPath" runat="server"></asp:TextBox>
<asp:FileUpload ID="FileUpload1" runat="server" Height="22px" Width="185px" />
<asp:Button ID="btnUpLoad" runat="server" Text="上传图片" />
<span style="color: #ff0033">如果不需要图片,则不需要上传</span></td>
<td bgcolor="#f6f6f6" style="height: 27px">
</td>
</tr>
<tr>
<td align="center" bgcolor="#f6f6f6" style="height: 27px">
公告详细信息:</td>
<td align="left" bgcolor="#f6f6f6" style="height: 27px">
<CE:Editor ID="Editor1" runat="server">
</CE:Editor>
</td>
<td bgcolor="#f6f6f6" style="height: 27px">
</td>
</tr>
<tr>
<td align="center" bgcolor="#f6f6f6" style="height: 27px">
</td>
<td align="left" bgcolor="#f6f6f6" style="height: 27px">
</td>
<td bgcolor="#f6f6f6" style="height: 27px">
</td>
</tr>
<tr>
<td align="center" bgcolor="#f6f6f6" style="height: 27px">
</td>
<td align="left" bgcolor="#f6f6f6" style="height: 27px">
<asp:Button ID="Button1" runat="server" Text="提 交" Width="104px" OnClick="Button1_Click" /></td>
<td bgcolor="#f6f6f6" style="height: 27px">
</td>
</tr>
</table>
protected void Button1_Click(object sender, EventArgs e)
{
DBNewsDetail news = new DBNewsDetail();
//common.check_str(this.Editor1.Text);
bool bl = news.AddNotice(common.FormatText(this.tbProductName), this.Editor1.Text, this.tbPicPath.Text);
if(bl==true)
{
common.ShowMsg("添加成功!", "NewsList.aspx");
}
else
{}
}
sql语句函数
public bool AddNotice(string Title, string Detail, string picPath)
{
string sql = @"insert into Notice(NoticeTitle,Detail,picPath,AddTime) values('" + Title + "','" + Detail + "','" + picPath + "','"+System.DateTime.Now.Date+"')";
try
{
int i = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql);
if (i > 0)
return true;
else
return false;
}
catch (Exception ex)
{
throw ex;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |