请问各位:程序运行时出现异常,异常信息为:引发类型为“System.Web.HttpUnhandledException”的异常。

shy06059 2010-05-28 09:55:55
请问各位:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Teacher_ThesisAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Sec.Authentication(false, false, true, false);
}

protected void btnNext_Click(object sender, EventArgs e)
{
if (true == AddRecord())
{
tbxCaption.Text = "";
tbxField.Text = "";
tbxContent.Text = "";
tbxRequirement.Text = "";

// ddlconstudy.SelectedValue="N";
// ddlconfact.SelectedValue = "N";



tbxMemo.Text = "";
tbxCaption.Focus();
}
}

protected void btnAdd_Click(object sender, EventArgs e)
{
if (true == AddRecord())
Response.Redirect("ThesisList.aspx");
}

protected bool AddRecord()
{
SqlConnection cn = Com.GetConnection();
// SqlCommand cmd = new SqlCommand(
// "insert into Thesis values(@caption,@content,@requirement,@field,@date,@memo,@teacherID,@specialtyID,null)", cn);

SqlCommand cmd = new SqlCommand(
"insert into Thesis values(@caption,@content,@requirement,@field,@constudy,@confact,@date,@memo,@teacherID,@specialtyID,null)", cn);


cmd.Parameters.AddWithValue("@caption", tbxCaption.Text);
cmd.Parameters.AddWithValue("@content", tbxContent.Text);
cmd.Parameters.AddWithValue("@requirement", tbxRequirement.Text);
cmd.Parameters.AddWithValue("@field", tbxField.Text);

cmd.Parameters.AddWithValue("@constudy", ddlconstudy.SelectedValue);
cmd.Parameters.AddWithValue("@confact", ddlconfact.SelectedValue);





cmd.Parameters.AddWithValue("@date", DateTime.Now);
cmd.Parameters.AddWithValue("@memo", tbxMemo.Text);
cmd.Parameters.AddWithValue("@teacherID", Session["LoginID"].ToString());
cmd.Parameters.AddWithValue("@specialtyID", ddlSpecialty.SelectedValue);
cn.Open();
cmd.ExecuteNonQuery();
// cmdresults = cmd.ExecuteNonQuery()
cn.Close();
return true;
}
}
问题补充:cmd.ExecuteNonQuery();//(在这里提示有错)

将字符串转换为 smalldatetime 数据类型时失败。
...全文
1479 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
print(”hello,world!“);

 

williamxia8 2013-02-18
  • 打赏
  • 举报
回复
知道问题了,应该是界面上面的某些元素出现小问题,比如我的问题就是GridView里面有三列,都放置了控件,当时因为是拷贝过去,把三列的控件ID名字都弄成一样的了,所以就出现这个问题了。 只要把名字改为不一样的就可以了。
gwhzh 2010-10-07
  • 打赏
  • 举报
回复
看看是不是时间的值超过范围了。
shy06059 2010-05-29
  • 打赏
  • 举报
回复
我改成datetime一样的出错!郁闷....
FootMan_BenBen 2010-05-29
  • 打赏
  • 举报
回复
你看看她需要什么样的格式插入才可以,把数据转换成需要的格式不就好了....
shy06059 2010-05-29
  • 打赏
  • 举报
回复
create table Thesis
(
thesisID int primary key identity, -- 论题ID 标识
caption nvarchar(100)not null, -- 论题标题
content nvarchar(2000), -- 论题内容
requirement nvarchar(2000), -- 要求及注意事项
field nvarchar(100), -- 涉及的专业领域
date smalldatetime not null default getdate(), -- 出题日期
memo nvarchar(1000), -- 备注信息

constudy nchar(1) not null check(constudy in('Y','N')), -- 是否结合科研
confact nchar(1) not null check(confact in('Y','N')), -- 是否结合实际


teacherID varchar(20) not null, -- 出题老师
specialtyID varchar(20) not null, -- 适用专业 面向专业
usedIntoYear smalldatetime, -- 使用年级(届) null为未使用

constraint FK_The_TeaID foreign key(teacherID) references Teacher(teacherID),
constraint FK_The_SpeID foreign key(specialtyID) references Specialty(specialtyID)
)


数据库文件
shy06059 2010-05-29
  • 打赏
  • 举报
回复
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ThesisAdd.aspx.cs" Inherits="Teacher_ThesisAdd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>添加论题</title>
<link href="../Css/com.css" rel="stylesheet" type="text/css">
</head>
<body bgColor="#799ae1" leftmargin="4" rightmargin="0" topmargin="4">
<form id="form1" runat="server">
<div style="margin:10px">

<table cellpadding="0" cellspacing="0" class="TableAll" width="700px">
<tr>
<td class="TableHead">
  添加论题
</td>
</tr>
<tr>
<td>
<div style="margin:10px; text-align:left;">
<table cellpadding="3" style="width: 653px">
<tr>
<td align="right" style="width: 79px" >
论题标题:</td>
<td >
<asp:TextBox ID="tbxCaption" runat="server" Width="300px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbxCaption" ErrorMessage="请输入标题!"/>
</td>
</tr>
<tr>
<td align="right" >
适用专业:</td>
<td >
<asp:SqlDataSource ID="dsSpecialty" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
SelectCommand="select specialtyID,name from Specialty" DataSourceMode="DataReader" ProviderName="<%$ ConnectionStrings:DBConnectionString.ProviderName %>"/>
<asp:DropDownList ID="ddlSpecialty" runat="server" DataSourceID="dsSpecialty" DataTextField="name" DataValueField="specialtyID" Width="200px" AppendDataBoundItems="True"/>
(该论题只能供所指定专业的学生使用)
</td>
</tr>
<tr>
<td align="right" style="width: 79px" >
专业领域:</td>
<td >
<asp:TextBox ID="tbxField" runat="server" Width="300px"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" style="width: 79px; height: 23px;" >
题目性质:</td>
<td style="height: 23px" >

<asp:DropDownList ID="ddlconfact" runat="server">
<asp:ListItem Selected="True" Value="Y">是</asp:ListItem>
<asp:ListItem Value="N">否</asp:ListItem>
</asp:DropDownList>(该题目是否结合实际)
</td>
</tr>

<tr>
<td align="right" style="width: 79px; height: 24px;" >
</td>
<td style="height: 24px" >

<asp:DropDownList ID="ddlconstudy" runat="server">
<asp:ListItem Selected="True" Value="Y">是</asp:ListItem>
<asp:ListItem Value="N">否</asp:ListItem>
</asp:DropDownList>(该题目是否结合科研)
</td>
</tr>
<tr>
<td align="right" style="width: 79px" >
内容:</td>
<td >
<asp:TextBox ID="tbxContent" runat="server" Height="200px" TextMode="MultiLine" Width="550px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 79px" >
要求:<br />
(注意事项)</td>
<td >
<asp:TextBox ID="tbxRequirement" runat="server" Height="100px" TextMode="MultiLine"
Width="550px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 79px" >
备注:</td>
<td >
<asp:TextBox ID="tbxMemo" runat="server" Height="80px" TextMode="MultiLine" Width="550px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 79px" >
</td>
<td >
</td>
</tr>
<tr>
<td align="right" style="width: 79px" >
</td>
<td align="right">
<asp:HyperLink ID="hlk" runat="server" NavigateUrl="ThesisList.aspx">[返回]</asp:HyperLink>      
<asp:Button ID="btnNext" runat="server" CssClass="Button" Text="下一条" OnClick="btnNext_Click" />
<asp:Button ID="btnAdd" runat="server" CssClass="Button" Text="添加" Width="53px" OnClick="btnAdd_Click" />
<input id="Reset1" class="Button" type="reset" value="清空" style="width:53px"/>
</td>
</tr>
</table>

</div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
这是.aspx文件!
shy06059 2010-05-29
  • 打赏
  • 举报
回复
我数据库里面的变量是smalldatetime类型。
用一楼,二楼的方法,问题依然存在!
T_long 2010-05-28
  • 打赏
  • 举报
回复
cmd.Parameters.AddWithValue("@date", DateTime.Now.ToShortDateString());
试一试反正就那几个函数,
看看你数据库里面是什么类型呢?
辰爸 2010-05-28
  • 打赏
  • 举报
回复
将字符串转换为 smalldatetime 数据类型时失败。

将时间那个字段转换下Convert(varchar(11),'date',112) 之后插入到数据库中!~

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧