注册 登录
编程论坛 ASP.NET技术论坛

测试时,为什么出错?

mao_x_r 发布于 2007-05-16 22:12, 1111 次点击
用visual 开发软件,测试时总是提示sqlDataAdapter1.Fill(dsAuthor)这句话出错,到底是什么原因呢?请各位高手指教,谢谢!
20 回复
#2
mao_x_r2007-05-16 22:15
我想插入图片让大家看看,怎么上传图片呢?
#3
tel19822007-05-16 22:15
把错误的原因发出来,或者把你的代码给出来,我们可以帮你看一下。
#4
mao_x_r2007-05-16 23:06
如何发代码呀?试了几次传不过来,急!急!急!
#5
xw2780932682007-05-16 23:40
我和你一样的错误呀,不知道什么原因
#6
mao_x_r2007-05-27 22:11
这错误到底怎么解决,请高手们一定要耐心指点一下.
#7
mao_x_r2007-05-27 22:17
[CODE]
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="mmApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 40px" runat="server" Width="432px" Height="176px" DataSource="<%# dsA0uthors1 %>" DataMember="goods" DataKeyField="goods_id" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="goods_id" SortExpression="goods_id" HeaderText="goods_id"></asp:BoundColumn>
<asp:BoundColumn DataField="goods_name" SortExpression="goods_name" HeaderText="goods_name"></asp:BoundColumn>
<asp:BoundColumn DataField="price" SortExpression="price" HeaderText="price"></asp:BoundColumn>
<asp:BoundColumn DataField="provider" SortExpression="provider" HeaderText="provider"></asp:BoundColumn>
<asp:BoundColumn DataField="more" SortExpression="more" HeaderText="more"></asp:BoundColumn>
</Columns>
</asp:DataGrid></FONT>
</form>
</body>
</HTML>[/CODE]
#8
mao_x_r2007-05-27 22:18
上面是主文件代码,再发一个后台文件代码
#9
mao_x_r2007-05-27 22:19

[CODE]using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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 mmApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected mmApplication1.dsA0uthors dsA0uthors1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
Bind();
}
}

public void Bind()
{
sqlDataAdapter1.Fill(dsAOuthors1);
DataGrid1.DataSource=dsAOuthors1;
DataGrid1.DataBind();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.dsA0uthors1 = new mmApplication1.dsA0uthors();
((System.ComponentModel.ISupportInitialize)(this.dsA0uthors1)).BeginInit();
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT id, goods_id, goods_name, price, provider, more FROM goods";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO goods(goods_id, goods_name, price, provider, more) VALUES (@goods_id," +
" @goods_name, @price, @provider, @more); SELECT id, goods_id, goods_name, price," +
" provider, more FROM goods WHERE (id = @@IDENTITY)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goods_id", System.Data.SqlDbType.Int, 4, "goods_id"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goods_name", System.Data.SqlDbType.VarChar, 50, "goods_name"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@price", System.Data.SqlDbType.Money, 8, "price"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@provider", System.Data.SqlDbType.VarChar, 50, "provider"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@more", System.Data.SqlDbType.VarChar, 50, "more"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE goods SET goods_id = @goods_id, goods_name = @goods_name, price = @price, provider = @provider, more = @more WHERE (id = @Original_id) AND (goods_id = @Original_goods_id) AND (goods_name = @Original_goods_name) AND (more = @Original_more OR @Original_more IS NULL AND more IS NULL) AND (price = @Original_price OR @Original_price IS NULL AND price IS NULL) AND (provider = @Original_provider OR @Original_provider IS NULL AND provider IS NULL); SELECT id, goods_id, goods_name, price, provider, more FROM goods WHERE (id = @id)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goods_id", System.Data.SqlDbType.Int, 4, "goods_id"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goods_name", System.Data.SqlDbType.VarChar, 50, "goods_name"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@price", System.Data.SqlDbType.Money, 8, "price"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@provider", System.Data.SqlDbType.VarChar, 50, "provider"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@more", System.Data.SqlDbType.VarChar, 50, "more"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_id", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goods_id", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goods_id", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goods_name", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goods_name", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_more", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "more", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_price", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "price", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_provider", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "provider", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.Int, 4, "id"));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM goods WHERE (id = @Original_id) AND (goods_id = @Original_goods_id) AND (goods_name = @Original_goods_name) AND (more = @Original_more OR @Original_more IS NULL AND more IS NULL) AND (price = @Original_price OR @Original_price IS NULL AND price IS NULL) AND (provider = @Original_provider OR @Original_provider IS NULL AND provider IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_id", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goods_id", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goods_id", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goods_name", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goods_name", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_more", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "more", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_price", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "price", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_provider", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "provider", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=515461FB4184469;packet size=4096;integrated security=SSPI;data sou" +
"rce=localhost;persist security info=False;initial catalog=wlb";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "goods", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("id", "id"),
new System.Data.Common.DataColumnMapping("goods_id", "goods_id"),
new System.Data.Common.DataColumnMapping("goods_name", "goods_name"),
new System.Data.Common.DataColumnMapping("price", "price"),
new System.Data.Common.DataColumnMapping("provider", "provider"),
new System.Data.Common.DataColumnMapping("more", "more")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// dsA0uthors1
//
this.dsA0uthors1.DataSetName = "dsA0uthors";
this.dsA0uthors1.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dsA0uthors1)).EndInit();

}
#endregion
}
}

[/CODE]

#10
mao_x_r2007-05-27 22:24
[IMG]http://192.168.1.2/E:/111.jpg[/IMG]
#11
mao_x_r2007-05-27 22:24
[IMG]http://192.168.1.2/111.jpg[/IMG]
#12
mao_x_r2007-05-27 22:25
只有本站会员才能查看附件,请 登录

#13
mao_x_r2007-05-27 22:26
只有本站会员才能查看附件,请 登录

#14
mao_x_r2007-05-27 22:28
以上是调试出错的图片,害苦我了,专家们真的要出手相助了!
#15
mao_x_r2007-05-28 09:40
等了好久,请高手们不吝赐教.真的有急用!
#16
GrimFish2007-05-28 09:53

太乱了

给SQL里添加ASPNET用户,并给权限。

#17
mao_x_r2007-05-28 10:14
我已经有用户呀,在哪里、怎么设置权限呢?
#18
GrimFish2007-05-28 10:19
SQL数据库里添加这个用户。
或者你可以改用SA来查询数据库。
#19
mao_x_r2007-05-28 10:43
哦!
#20
初学Delphi2007-05-28 15:06

最烦看那么多的代码,看着就头晕,有时候自己写的都晕了

那里不是提示你登陆失败么?
所以你的da执行不料查询。你fill肯定报错了

#21
mao_x_r2007-05-29 09:26
改用SA来查询数据库真的成功了,谢谢,fill语句好象没问题,但谢谢提醒!
1