适配器错误.填充
本文关键字:填充 错误 适配器 | 更新日期: 2023-09-27 17:58:06
这是我的c#
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
public partial class _Update : System.Web.UI.Page
{
protected void UpdateAccount(object sender, EventArgs e)
{
using (SqlConnection myConn = new SqlConnection(ConfigurationManager.AppSettings["connString"]))
using (SqlCommand myCommand = new SqlCommand("UPDATE_ACCOUNT_DETAILS", myConn))
using (DataSet dsBank = new DataSet())
{
string commandSql = "SELECT * FROM CARDHOLDER_ACCOUNT_DETAILS WHERE CARD_NUMBER = " + txt_CurrCardNumber;
string bankId = null;
string name = null;
string address = null;
string cardNumber = null;
string balance = null;
SqlCommand myCommand2 = new SqlCommand(commandSql, myConn);
SqlDataAdapter myAdaptor = new SqlDataAdapter(myCommand2);
{
myConn.Open();
myAdaptor.Fill(dsBank);
bankId = dsBank.Tables[0].Rows[0]["BANK_ID"].ToString();
name = dsBank.Tables[0].Rows[0]["NAME"].ToString();
address = dsBank.Tables[0].Rows[0]["ADDRESS1"].ToString();
cardNumber = dsBank.Tables[0].Rows[0]["CARD_NUMBER"].ToString();
balance = dsBank.Tables[0].Rows[0]["BALANCE"].ToString();
string NewBankIdInsert = null;
if (int.Parse(txt_NewBankId.Text) > 5 || int.Parse(txt_NewBankId.Text) < 1)
{
NewBankIdInsert = "";
}
else
{
NewBankIdInsert = txt_NewBankId.Text;
}
if (txt_CurrBankId.Text != bankId || txt_CurrName.Text != name || txt_CurrCardNumber.Text != cardNumber || txt_CurrAddress.Text != address)
{
txt_AccountMade.Text = "We could not update your account, check if you have inserted incorrect details.";
}
else
{
myCommand.CommandType = CommandType.StoredProcedure;
if (NewBankIdInsert == "")
{
myCommand.Parameters.Add("@NEW_BANK_ID", SqlDbType.Int).Value = 999999;
}
else
{
myCommand.Parameters.Add("@NEW_BANK_ID", SqlDbType.Int).Value = int.Parse(NewBankIdInsert);
}
myCommand.Parameters.Add("@NEW_CARD_NUMBER", SqlDbType.VarChar, 50).Value = txt_NewCardNumber;
myCommand.Parameters.Add("@NEW_NAME", SqlDbType.VarChar, 50).Value = txt_NewName;
myCommand.Parameters.Add("@NEW_ADDRESS1", SqlDbType.VarChar, 50).Value = txt_NewAddress;
myCommand.Parameters.Add("@OLD_CARD_NUMBER", SqlDbType.VarChar).Value = cardNumber;
Random rnd = new Random();
int New_balance = rnd.Next(1000, 10000);
if (New_balance == int.Parse(balance))
{
New_balance += 1000;
if (New_balance > 10000)
{
New_balance -= 2000;
}
}
if (txt_NewCardNumber.Text != cardNumber && txt_NewBankId.Text != bankId)
{
myCommand.Parameters.Add("@NEW_BALANCE", SqlDbType.Int).Value = New_balance;
}
else
{
myCommand.Parameters.Add("@NEW_BALANCE", SqlDbType.Int).Value = int.Parse(balance);
}
}
myCommand.ExecuteNonQuery();
txt_AccountMade.Text = "Your account details have been changed.";
}
}
}
}
这是我的html
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Update_Account.aspx.cs" Inherits="_Update" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD/ XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Bank Management</title>
</head>
<body style="text-align:center">
<form id="form1" runat="server">
<div>
<h1 style="font-size:125%;">Insert Your Details Below</h1>
<br />
<br />
<br />
<h1 style="font-size:80%;">Bank-Id</h1>
<asp:TextBox ID="txt_CurrBankId" runat="server" Width="380px"></asp:TextBox>
<br />
<h1 style="font-size:80%;">Card Number</h1>
<asp:TextBox ID="txt_CurrCardNumber" runat="server" Width="380px"></asp:TextBox>
<br />
<h1 style="font-size:80%;">Name</h1>
<asp:TextBox ID="txt_CurrName" runat="server" Width="380px"></asp:TextBox>
<br />
<h1 style="font-size:80%;">Address</h1>
<asp:TextBox ID="txt_CurrAddress" runat="server" Width="380px"></asp:TextBox>
<br />
<h1 style="font-size:125%;">Insert Your Details Below</h1>
<br />
<br />
<br />
<h1 style="font-size:80%;">Bank-Id</h1>
<asp:TextBox ID="txt_NewBankId" runat="server" Width="380px"></asp:TextBox>
<br />
<h1 style="font-size:80%;">Card Number</h1>
<asp:TextBox ID="txt_NewCardNumber" runat="server" Width="380px"></asp:TextBox>
<br />
<h1 style="font-size:80%;">Name</h1>
<asp:TextBox ID="txt_NewName" runat="server" Width="380px"></asp:TextBox>
<br />
<h1 style="font-size:80%;">Address</h1>
<asp:TextBox ID="txt_NewAddress" runat="server" Width="380px"></asp:TextBox>
<br />
<asp:Button ID="btn_Invoke" runat="server" Width="380px" OnClick="UpdateAccount" Text="Finish" stlyle=":;" />
<br />
<asp:Textbox ID="txt_AccountMade" runat="server" Width ="380px"
ReadOnly="true"></asp:TextBox>
</div>
</form>
</body>
</html>
我的myAdaptor.Fill(dsBank)出现错误我得到错误
System.Data.dll中发生类型为"System.Data.SqlClient.SqlException"的异常,但未在用户代码中处理
附加信息:无法绑定多部分标识符"System.Web.UI.WebControls.TextBox"。
(错误结束)我有一段代码,基本上是这样的,但没有html(是一个web服务),我基本上是复制/粘贴它,更改了一些变量,这很有效,所以我不明白为什么不这样做。
提前感谢!!!
关于文本框的问题,您可以使用css对文本框进行如下样式设置:
textbox {
display: inline-block
}
您的代码应该是txt_CurrCardNumber.Text
尝试下面的代码,它可能会工作
Sql查询字符串
字符串命令Sql=";从cardcard_ACCOUNT_DETAILS中选择*,其中CARD_NUMBER="+txt_CurrCardNumber;
使用SqlDataAdapter
SqlDataAdapter myAdaptor=新的SqlDataAdapter(命令Sql,myConn);
myAdaptor.Fill(dsBank);
使用SqlCommand
SqlCommand myCommand2=新的SqlCommand(commandSql,myConn);
myConn.open();
myCommand2.ExecuteNonquery();
myCommand2.Fill(dsBank);
myConn.Close();