我有个网页,想要把数据写到Access的Task数据库里的表里,代码都没出现错误,但是数据写不进去,请高手帮我看看是什么问题
Task数据库有两张表 分别是types 和 btask
types:id typename
btask: ID title price typeid content into time
页面设计 task.aspx
<%@ Page Language="C#" CodeFile ="task.aspx.cs" Inherits =task %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" language="jscript">
<head runat="server">
<title>Untitled Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><style type="text/css">
<!--
body {margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;}
.STYLE1 {font-size: 15px;
font-weight: bold;}
.STYLE3 {font-size: 24px}
.STYLE12 {color: #FF0000}
.s1 {font-size: small;}
-->
</style>
<script type="text/JavaScript">
</script>
</head>
<body text="#00">
<form id="form1" runat="server">
<div>
<img src="image/新做/a_01.gif" width="988" height="73" /></div>
<p><span class="STYLE1"> </span></p>
<p><span class="STYLE1"> <img src="image/按钮/20070930103049465.gif" width="48" height="26" /> 填写任务信息</span></p>
<p> </p>
<p> <img src="image/按钮/20070930100040876.gif" width="19" height="16" /><strong style="font-size: small"> 填写任务信息 <span class="STYLE3">→</span> </strong><img src="image/按钮/20070930100040802.gif" width="19" height="16" /><strong style="font-size: small"> 预付任务款</strong> <strong><span class="STYLE3">→</span></strong> <img src="image/按钮/20070930100040603.gif" width="19" height="16" /><strong style="font-size: small"> 客服审核任务 <span class="STYLE3"> →</span> </strong><img src="image/按钮/20070930100040959.gif" width="19" height="16" /><strong style="font-size: small"> 任务在网站发布</strong></p>
<p> </p>
<p> <span class="STYLE1"><img src="image/按钮/20070930103049471.gif" width="48" height="27" /> 任务信息</span> </p>
<p> </p>
<p style="font-size: small"> <span class="STYLE12">* </span>任务名称:<asp:TextBox
ID="txttitle" runat="server" Width="358px" ></asp:TextBox>
</p>
<p style="font-size: small">
<span class="STYLE12">* </span>任务金额:<asp:TextBox
ID="price" runat="server"></asp:TextBox>
元
<img src="image/新做/2.gif" style="z-index: -1; left: -11px; position: absolute;
top: 184px" tabindex="0" />
</p>
<p style="font-size: small"> <span class="STYLE12">*</span> 任务类别:<asp:DropDownList ID="category" runat="server">
</asp:DropDownList><span class="grey9"></span></p>
<p style="font-size: small" align="justify"> <span class="STYLE12">*</span>任务描述:<asp:TextBox ID="content" runat="server" Height="114px" Width="349px"></asp:TextBox>
</p>
<p style="font-size: small" >
任务附件:<asp:FileUpload ID="fuUpload" runat="server" TabIndex="-1" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></p>
<p>
<asp:Button ID="Button2" runat="server" BackColor="White" BorderColor="Silver" BorderStyle="Dashed"
Text="保存到下一步" Width="146px" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" /></p>
</form>
</body>
</html>
Task数据库有两张表 分别是types 和 btask
types:id typename
btask: ID title price typeid content into time
页面设计 task.aspx
<%@ Page Language="C#" CodeFile ="task.aspx.cs" Inherits =task %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" language="jscript">
<head runat="server">
<title>Untitled Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><style type="text/css">
<!--
body {margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;}
.STYLE1 {font-size: 15px;
font-weight: bold;}
.STYLE3 {font-size: 24px}
.STYLE12 {color: #FF0000}
.s1 {font-size: small;}
-->
</style>
<script type="text/JavaScript">
</script>
</head>
<body text="#00">
<form id="form1" runat="server">
<div>
<img src="image/新做/a_01.gif" width="988" height="73" /></div>
<p><span class="STYLE1"> </span></p>
<p><span class="STYLE1"> <img src="image/按钮/20070930103049465.gif" width="48" height="26" /> 填写任务信息</span></p>
<p> </p>
<p> <img src="image/按钮/20070930100040876.gif" width="19" height="16" /><strong style="font-size: small"> 填写任务信息 <span class="STYLE3">→</span> </strong><img src="image/按钮/20070930100040802.gif" width="19" height="16" /><strong style="font-size: small"> 预付任务款</strong> <strong><span class="STYLE3">→</span></strong> <img src="image/按钮/20070930100040603.gif" width="19" height="16" /><strong style="font-size: small"> 客服审核任务 <span class="STYLE3"> →</span> </strong><img src="image/按钮/20070930100040959.gif" width="19" height="16" /><strong style="font-size: small"> 任务在网站发布</strong></p>
<p> </p>
<p> <span class="STYLE1"><img src="image/按钮/20070930103049471.gif" width="48" height="27" /> 任务信息</span> </p>
<p> </p>
<p style="font-size: small"> <span class="STYLE12">* </span>任务名称:<asp:TextBox
ID="txttitle" runat="server" Width="358px" ></asp:TextBox>
</p>
<p style="font-size: small">
<span class="STYLE12">* </span>任务金额:<asp:TextBox
ID="price" runat="server"></asp:TextBox>
元
<img src="image/新做/2.gif" style="z-index: -1; left: -11px; position: absolute;
top: 184px" tabindex="0" />
</p>
<p style="font-size: small"> <span class="STYLE12">*</span> 任务类别:<asp:DropDownList ID="category" runat="server">
</asp:DropDownList><span class="grey9"></span></p>
<p style="font-size: small" align="justify"> <span class="STYLE12">*</span>任务描述:<asp:TextBox ID="content" runat="server" Height="114px" Width="349px"></asp:TextBox>
</p>
<p style="font-size: small" >
任务附件:<asp:FileUpload ID="fuUpload" runat="server" TabIndex="-1" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></p>
<p>
<asp:Button ID="Button2" runat="server" BackColor="White" BorderColor="Silver" BorderStyle="Dashed"
Text="保存到下一步" Width="146px" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" /></p>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
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;
using System.Collections;
using System.Data.OleDb;
using System.IO;
using System.Text;
public partial class task : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ //定义连接字符串
string strConnnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
strConnnection += Server.MapPath(".\\App_Data\\Task.mdb");
//定义数据库连接,使用刚定义的哪个连接字符串
OleDbConnection myconn = new OleDbConnection(strConnnection);
//定义数据适配器,并申明SQL语句,数据库连接使用刚定义的连接
OleDbDataAdapter mycmd = new OleDbDataAdapter("select id ,typename from types", myconn);
//定义数据集
DataSet ds = new DataSet();
//填充数据集
mycmd.Fill(ds, "types");
//填充下拉框内容
this.category.DataSource = ds.Tables["types"].DefaultView;
//绑定DropDownList
category.DataTextField = "typename";
category.DataValueField = "id";
category.DataBind();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//创建上传文件的路径字符串
String savePath = Server.MapPath("file/");
//检查上传文件大小
if (fuUpload.PostedFile.ContentLength > 307200)
{
Label1.Text = "上传的文件不能超过140kb";
return;
}
//检查是否已经有同名的上传文件 if (fuUpload.HasFile)
{
String filename = fuUpload.FileName;//上传文件名
savePath += filename; //上传路经
fuUpload.SaveAs(savePath);//保存文件
}
//建立数据连接
string strConnnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
strConnnection += Server.MapPath(".\\App_Data\\Task.mdb");
OleDbConnection myconn = new OleDbConnection(strConnnection); string sql = "insert into btask(title,price,typeid,content,into,time)values";
sql += "('" + txttitle.Text + "','" + price.Text + "','" + category.SelectedItem.Value + "','" + content.Text + "','" + fuUpload.FileName.ToString() + "','" + DateTime.Now.ToString() + "')"; OleDbCommand mycmd = new OleDbCommand(sql, myconn);
mycmd.Connection.Open();
mycmd.ExecuteNonQuery();
mycmd.Connection.Close();
Response.Redirect("Default2.aspx");
} protected void Button1_Click(object sender, EventArgs e)
{
txttitle.Text = "";
price.Text = "";
content.Text = "";
}
}
sql += "('" + txttitle.Text + "','" + price.Text + "','" + category.SelectedItem.Value + "','" + content.Text + "','" + fuUpload.FileName.ToString() + "','" + DateTime.Now.ToString() + "')";
地方时在查询分析器里执行 sql的字符串是否可以成功执行
string sql = "insert into btask(title,price,typeid,content,into,time)values";
sql += "'" + txttitle.Text + "','" + price.Text + "','" + category.SelectedItem.Text+ "','" + content.Text + "','" + fuUpload.FileName.ToString() + "','" + DateTime.Now.ToString() + "'";
你的报什么错?string sql = "insert into btask(title,price,typeid,content,into,time)values('" + txttitle.Text + "','" + price.Text + "','" + category.SelectedItem.Text+ "','" + content.Text + "','" + fuUpload.FileName.ToString() + "','" + DateTime.Now.ToString() + "')";