主题:  存储数据出错

eShaka

职务:版主
等级:6
金币:15.0
发贴:5019
#12004/9/29 17:37:46
addBlog.aspx
<%@ Page language="c#" Codebehind="addBlog.aspx.cs" AutoEventWireup="false" Inherits="blog.admin.addBlog" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>add</title>
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="C#" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
		<LINK href="../inc/style.css" type="text/css" rel="stylesheet">
	</HEAD>
	<body>
		<form runat="server">
			<table cellSpacing="0" cellPadding="0" width="760" align="center" border="0">
				<tr>
					<td width="180" bgColor="#999999">&nbsp;<FONT face="宋体">&nbsp;&nbsp; </FONT>
					</td>
					<td width="580">
						<table cellSpacing="0" cellPadding="0" width="100%" align="right" border="0">
							<tr>
								<td align="right" width="18%" height="30">所属分类:</td>
								<td width="82%"><asp:dropdownlist id="kindBlog" runat="server"></asp:dropdownlist></td>
							</tr>
							<tr>
								<td align="right" height="30">Blog标题:</td>
								<td><asp:textbox id="titleBlog" runat="server"></asp:textbox></td>
							</tr>
							<tr>
								<td align="right" height="30">Blog摘要:</td>
								<td><asp:textbox id="summaryBlog" runat="server" Height="64px" Width="464px" TextMode="MultiLine"></asp:textbox></td>
							</tr>
							<tr>
								<td align="right">Blog正文:</td>
								<td height="300"><asp:textbox id="textBlog" runat="server" Height="288px" Width="464px" TextMode="MultiLine"></asp:textbox></td>
							</tr>
							<tr>
								<td align="right" height="50">上传附件:</td>
								<td>&nbsp;<FONT face="宋体">updata</FONT></td>
							</tr>
							<tr>
								<td align="right" height="30">发布选项:</td>
								<td></td>
							</tr>
							<tr>
								<td align="right">定时发布:</td>
								<td>&nbsp;</td>
							</tr>
							<tr>
								<td align="right" height="30">&nbsp;</td>
								<td>&nbsp;
									<asp:button id="up" runat="server" Text="提交"></asp:button></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</form>
	</body>
</HTML>


addBlog.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace blog.admin
{
	/// <summary>
	/// addBlog 的摘要说明。
	/// </summary>
	public class addBlog : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DropDownList kindBlog;
		protected System.Web.UI.WebControls.TextBox titleBlog;
		protected System.Web.UI.WebControls.TextBox summaryBlog;
		protected System.Web.UI.WebControls.TextBox textBlog;
		protected System.Web.UI.WebControls.Button up;
		protected System.Data.SqlClient.SqlConnection sqlConnectionBlog;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.sqlConnectionBlog = new System.Data.SqlClient.SqlConnection();
			// 
			// sqlConnectionBlog
			// 
			this.sqlConnectionBlog.ConnectionString = "workstation id=\"YT-ESHAKA\";packet size=4096;user id=sa;data source=\"YT-ESHAKA\";pe" +
				"rsist security info=True;initial catalog=blog;password=shaka";
			this.up.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			string  strInsert;
			SqlCommand cmdInsert;

			strInsert = "Insert blog ( titleBlog ) Values ( @titleBlog )";
			cmdInsert = new SqlCommand( strInsert, sqlConnectionBlog );
			cmdInsert.Parameters.Add( "@titleBlog", SqlDbType.VarChar ).Value = titleBlog.Text;
			sqlConnectionBlog.Open();
			cmdInsert.ExecuteNonQuery();
			sqlConnectionBlog.Close();
		}

	}
}


总是存不进去



缺缺

职务:管理员
等级:8
金币:41.0
发贴:9620
#22004/9/29 17:50:42
报错了么?



eShaka

职务:版主
等级:6
金币:15.0
发贴:5019
#32004/9/29 19:05:16
点了提交后
“/blog”应用程序中的服务器错误。
--------------------------------------------------------------------------------

对象名 'blog' 无效。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Data.SqlClient.SqlException: 对象名 'blog' 无效。

源错误: 


行 67: 			cmdInsert.Parameters.Add( "@titleBlog", SqlDbType.VarChar ).Value = titleBlog.Text;
行 68: 			sqlConnectionBlog.Open();
行 69: 			cmdInsert.ExecuteNonQuery();
行 70: 			sqlConnectionBlog.Close();
行 71: 		}
 

源文件: f:\web\blog\admin\addblog.aspx.cs    行: 69 

堆栈跟踪: 


[SqlException: 对象名 'blog' 无效。]
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +196
   blog.admin.addBlog.Button1_Click(Object sender, EventArgs e) in f:\web\blog\admin\addblog.aspx.cs:69
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1277

 


--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573 



eShaka

职务:版主
等级:6
金币:15.0
发贴:5019
#42004/9/30 9:17:45
我的数据库里可是绝对有blog表的啊



缺缺

职务:管理员
等级:8
金币:41.0
发贴:9620
#52004/9/30 13:27:13
执行一下
Select * from sysobjects WHERE type = 'u'
看看得到的结果