- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在 Visual Studio 2013 中使用 ASP.NET C# 创建一个简单的注册页面。
我在单击提交按钮以确保注册详细信息进入我尝试连接的数据库时遇到了以下错误。
Error:System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'B'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource
1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Registration.submitButton_Click(Object sender, EventArgs e) in d:\Desktop\IIPWebsite\Registration.aspx.cs:line 56 ClientConnectionId:41bb1e5f-3298-4b70-89d6-b12d0519ea55
我的aspx页面代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Registration.aspx.cs" Inherits="Registration" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NHH Consultants</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700,900" rel="stylesheet" />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
<link href="fonts.css" rel="stylesheet" type="text/css" media="all" />
<!--[if IE 6]>
< link href="default_ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->
<style type="text/css">
.style1
{
font-size: 1em;
}
.style3
{
font-size: 4em;
}
.style4
{
width: 208px;
}
.style2
{
width: 126px;
}
.style6
{
font-size: medium;
color: #FFFFFF;
}
.style7
{
text-align: center;
font-size: 30pt;
color: #FFFFFF;
}
.style8
{
color: #FF9933;
}
.auto-style1 {
width: 261px;
}
.auto-style2 {
width: 126px;
height: 27px;
}
.auto-style3 {
width: 208px;
height: 27px;
}
.auto-style4 {
width: 261px;
height: 27px;
}
.auto-style12 {
width: 152px;
height: 26px;
}
.auto-style14 {
width: 261px;
height: 26px;
}
.auto-style23 {
width: 152px;
height: 29px;
}
.auto-style25 {
width: 261px;
height: 29px;
}
.auto-style26 {
width: 206px;
}
.auto-style27 {
width: 206px;
height: 26px;
}
.auto-style28 {
width: 206px;
height: 29px;
}
.auto-style29 {
font-size: medium;
color: #FFFFFF;
width: 152px;
}
.auto-style30 {
width: 152px;
}
</style>
</head>
<body>
<form id="form" runat="server">
<div id="header-wrapper"
style="background-image: url('images/NYC_Night.jpg')">
<div id="header-wrapper2">
<div id="header" class="container">
<div id="logo">
<h1 style="color: #FFFFFF">NHH Consultants</h1>
</div>
<div id="menu">
<ul>
<li class="current_page_item"><a href="#" accesskey="1" title="">Homepage</a></li>
<li><a href="#" accesskey="2" title="">LOGIN</a></li>
<li><a href="#" accesskey="3" title="">About Us</a></li>
<li><a href="#" accesskey="4" title="">Contact Us</a></li>
<li><a href="#" accesskey="4" title="">Services</a></li>
<li></li>
</ul>
</div>
</div>
<div class="major">
<h2 class="style3">reliability, Anytime, anywhere</h2>
<span class="style1">Your number one electrical & mechanical engineering
consultant</span> </div>
</div>
</div>
<div id="wrapper1" class="style7">
<strong>Registration
<br />
"*" Denotes field is compulsory</strong></div>
<table class="style1">
<tr>
<td class="auto-style29">
*Username:</td>
<td class="style4">
<asp:TextBox ID="userTB" runat="server" Width="180px"> </asp:TextBox>
</td>
<td class="auto-style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="userTB" ErrorMessage="Username is required!"
ForeColor="Red" CssClass="style8"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style29">
*Password:</td>
<td class="style4">
<asp:TextBox ID="passTB" runat="server" Width="180px" TextMode="Password" ViewStateMode="Disabled"> </asp:TextBox>
</td>
<td class="auto-style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="passTB" ErrorMessage="Password is required!"
ForeColor="Red" CssClass="style8"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style29">
*Confirm Password:</td>
<td class="style4">
<asp:TextBox ID="confirmTB" runat="server" Width="180px" TextMode="Password"> </asp:TextBox>
</td>
<td class="auto-style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="confirmTB" ErrorMessage="Confirmation of password is required!"
ForeColor="Red" CssClass="style8"></asp:RequiredFieldValidator>
<br />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="passTB" ControlToValidate="confirmTB"
ErrorMessage="Passwords do not match!" ForeColor="Red" CssClass="style8"></asp:CompareValidator>
</td>
</tr>
<tr>
<td class="auto-style29">
*Email:</td>
<td class="style4">
<asp:TextBox ID="emailTB" runat="server" Width="180px"> </asp:TextBox>
</td>
<td class="auto-style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="emailTB" ErrorMessage="Email is required!"
ForeColor="Red" CssClass="style8"></asp:RequiredFieldValidator>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="emailTB" ErrorMessage="Email is invalid!" ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
CssClass="style8"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style29">
*Company name:</td>
<td class="style4">
<asp:TextBox ID="companyTB" runat="server" Width="180px"> </asp:TextBox>
</td>
<td class="auto-style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="companyTB" ErrorMessage="Company is required!"
ForeColor="Red" CssClass="style8"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style30" style="color: #FFFFFF">
*First name:</td>
<td class="style4">
<asp:TextBox ID="firstnameTB" runat="server" Width="180px"></asp:TextBox>
</td>
<td class="auto-style1" title="First name is required!">
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="firstnameTB" ErrorMessage="First name is required!" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
<table class="style1">
<tr>
<td class="auto-style30" style="color: #FFFFFF">*Last name:</td>
<td class="auto-style26">
<asp:TextBox ID="lastnameTB" runat="server" Width="179px"></asp:TextBox>
</td>
<td class="auto-style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="Last name is required!" ControlToValidate="lastnameTB" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style12" style="color: #FFFFFF">*Address:</td>
<td class="auto-style27">
<asp:TextBox ID="addressTB" runat="server" Width="180px"></asp:TextBox>
</td>
<td class="auto-style14">
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="Address is required!" ControlToValidate="addressTB" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style30" style="color: #FFFFFF">*Postal Code:</td>
<td class="auto-style26">
<asp:TextBox ID="postalcodeTB" runat="server" Width="180px"></asp:TextBox>
</td>
<td class="auto-style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ErrorMessage="Postal Code is required!" ControlToValidate="postalcodeTB" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="postalcodeTB" ErrorMessage="Postal code is invalid!" ForeColor="Red" ValidationExpression="\d{6}(\d{4})?$"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style12" style="color: #FFFFFF">*Contact Number:</td>
<td class="auto-style27">
<asp:TextBox ID="contactnumberTB" runat="server" Width="180px"></asp:TextBox>
</td>
<td class="auto-style14">
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ErrorMessage="Contact number is required!" ControlToValidate="contactnumberTB" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="contactnumberTB" ErrorMessage="Contact number is invalid!" ForeColor="Red" ValidationExpression="^[689]\d{7}$"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style23" style="color: #FFFFFF">
<br />
Date of Birth:</td>
<td class="auto-style28" style="color: Red">
<asp:Label ID="dateLabel" runat="server" ForeColor="#FFFF66" Text="Date in YYYY-MM-DD format" Visible="True"></asp:Label>
<br />
<asp:TextBox ID="dateTB" runat="server" Width="180px"></asp:TextBox>
</td>
<td class="auto-style25" style="color: Red">
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="dateTB" ErrorMessage="Date is invalid!" ForeColor="Red" ValidationExpression="^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style30" style="color: #FFFFFF">City:</td>
<td class="auto-style26">
<asp:TextBox ID="cityTB" runat="server" Width="180px"></asp:TextBox>
</td>
<td class="auto-style1"> </td>
</tr>
<tr>
<td class="auto-style30" style="color: #FFFFFF">Fax number:</td>
<td class="auto-style26">
<asp:TextBox ID="faxTB" runat="server" Width="180px"></asp:TextBox>
</td>
<td class="auto-style1"> </td>
</tr>
<tr>
<td class="auto-style30"> </td>
<td class="auto-style26"> </td>
<td class="auto-style1"> </td>
</tr>
</table>
<table class="style1">
<tr>
<td class="auto-style2">
</td>
<td class="auto-style3">
</td>
<td class="auto-style4">
<asp:Button ID="submitButton" runat="server" onclick="submitButton_Click"
Text="Submit" Height="23px" Width="97px" />
<asp:Button ID="resetButton" runat="server" onclick="resetButton_Click" Text="Reset fields" Height="23px" Width="97px" />
</td>
</tr>
</table>
</form>
<div id="wrapper">
</div>
</form>
</body>
</html>
虽然我的aspx.cs页面代码如下:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisterConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from Client where cUserName= '" + userTB.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("Username is already taken! Please choose another username.");
}
conn.Close();
}
}
protected void submitButton_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisterConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into Client (cFirstName, cLastName, cD.O.B, cCompanyName, cAddress, cCity, cZipCode, cPhoneNo, cFax, cEmail, cUsername, cPassword) values (@firstname,@lastname,@dob,@companyname,@address,@city,@zipcode,@phoneno,@fax,@email,@username,@password)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@firstname", firstnameTB.Text);
com.Parameters.AddWithValue("@lastname", lastnameTB.Text);
com.Parameters.AddWithValue("@dob", dateTB.Text);
com.Parameters.AddWithValue("@companyname", companyTB.Text);
com.Parameters.AddWithValue("@address", addressTB.Text);
com.Parameters.AddWithValue("@city", cityTB.Text);
com.Parameters.AddWithValue("@zipcode", postalcodeTB.Text);
com.Parameters.AddWithValue("@phoneno", contactnumberTB.Text);
com.Parameters.AddWithValue("@fax", faxTB.Text);
com.Parameters.AddWithValue("@email", emailTB.Text);
com.Parameters.AddWithValue("@username", userTB.Text);
com.Parameters.AddWithValue("@password", passTB.Text);
com.ExecuteNonQuery();
Response.Write("Congratulations! Your registration is successful!");
Response.Redirect("ClientLogin.aspx");
conn.Close();
}
catch (Exception ex)
{
Response.Write("Error:" + ex.ToString());
}
}
protected void resetButton_Click(object sender, EventArgs e)
{
Response.Redirect("Registration.aspx");
}
}
最佳答案
您正在尝试将数据插入到数据库中名为 c.D.O.B. 的字段中。将它括在方括号中,事情应该可以工作,即
insert into Client (cFirstName, cLastName, [cD.O.B], ...
如果您对数据库设计有任何影响,请确保将该列名称更改为更合理的名称。列名称中的句点不适用于许多工具,并且在这里的附加值非常小。
关于c# - System.Data.SqlClient.SqlConnection 错误 : Invalid column name 'B' .,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27752456/
这正确地呈现了标题,因为我可以看到一个列带有“Product ID”标题的表:。我正试图重构它,这样我就可以重用它,因为它们在整个应用程序中几乎是相同的:。在这种情况下,头不会呈现...检查页面元素中
我什至不知道如何表达这一点,但在 Python 中有没有一种方法可以引用等号之前的文本,而无需实际再次编写? ** 编辑 - 我在 Jupyter 中使用 python3 我似乎用了半辈子的时间来写作
假设我有一个包含以下列的字典 dict_ = [ {'key1': 'value1', 'key2': 'value2', 'key3': 'value3', '
假设我有一个包含以下列的字典 dict_ = [ {'key1': 'value1', 'key2': 'value2', 'key3': 'value3', '
假设我的数据库中有一张地铁 map ,其中每条线路的每个站点都是一行。如果我想知道我的线路在哪里互连: mysql> SELECT LineA.stop_id FROM LineA, LineB WH
代码 select c1,c2,c3,c4,c5,c6 from table where c5 in ('a', 'b') 从这里开始,我想将 c5 列拆分为两列,然后根据它们对 c
我正在尝试搜索表格中的两列,即标题和描述。但我想先搜索标题,然后再搜索描述。所以匹配标题的所有行排在第一位,所有匹配描述的行排在第二位 我可以使用单个 SQL 查询来实现吗? 最佳答案 您还可以使用
下面有以下 Python 数据框。 “标志”字段是我想要用代码创建的所需列。 我想要执行以下操作: 如果“分配类型”是预测的并且“Activities_Counter”大于 10,我想创建一个名为“F
我有两列,area 和 block,其中 area 是一个 int 类型,block 是一个 varchar。 现在我正在写两个查询: select * from table where area a
使用 Slick 2,我试图生成一个带有元组 IN 子句的查询: select * from my_table where (a, b) IN ((1, 87)); 给定: val seq: Seq[
我正在尝试从数据透视表中获取一组值,其中 A 列等于值数组,例如 ID 12 的 attribute_value_id 等于 3 和 9。这可以做到吗?我已经走了这么远... ID | post_id
我找不到这样做的有效方法。我在 Python 中有以下 DataFrame,列从 A 到 Z A B C ... Z 0 2.0 8.0 1.0 ... 5.0 1
我的数据框中有以下格式的数据: >>> df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD')) >>> df
我有多个与我公司销售的产品相关的表被新产品取代,随着时间的推移,这导致了多个表的出现。 我一遍又一遍地使用以下查询,直到最终表中只剩下 2 个产品... CREATE TABLE mar15a
我有如下 2 个表:- 表A ------------------------------- | product_id | price | --------------------
我有一个名为 tbl_mainsheet7 的表,创建方式如下: pk_mainsheet client_id project_id mainsheet_id project_cat EA_
我得到了以下 HTML 结构: ... ... 我的 CSS: #main-container { width:80%; margin:20px auto;
对于我的以下要求,我无法获得解决方案。 如果 data.table(如下)在 Col1 和 Col3 中有匹配的值。替换 Col2 值(旧的 New-Val)。 Col1 Col2 Col3
我正在通过连接几个表来构建一个 View ,以通过 Entity Framework 提取数据。由于此 View 没有唯一列,EntityFramework 无法检索正确的结果集(即第一列重复)。 为
好的,我已经尝试了太久了,是时候寻求帮助了。我有一个看起来有点像这样的数据框: person fruit quantity all_fruits 0 p1 grapes 2
我是一名优秀的程序员,十分优秀!