我在 visual studio 2019 中使用 asp.net 和 c# 创建了一个 Web 表单,这是编程的新手,所以这可能是一个简单的解决问题,当我运行代码时,我得到 System.Data.SqlClient.SqlException: 'Incorrect syntax near ' F'。 字符串 ')' 后的引号不闭合。 我不知道为什么
我试图寻找未闭合的引号,但我找不到任何
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace site.pages
{
public partial class register : System.Web.UI.Page
{
public string st = "";
public string msg = "";
public string sqlmsg = "";
public string yrborn = "";
public string tableByform;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["submit"] != null)
{
string fileName = "userDB.mdf";
string tableName = "usersTbl";
string uname = Request.Form["uname"];
string Fname = Request.Form["Fname"];
string lname = Request.Form["lname"];
string email = Request.Form["email"];
string yearBorn = Request.Form["YearBorn"];
string gender = Request.Form["gender"];
string City = Request.Form["City"];
string Password = Request.Form["password"];
string verify_password = Request.Form["vpassword"];
string hobies = Request.Form["hobies"].ToString();
char hob1 = 'F';
char hob2 = 'F';
char hob3 = 'F';
char hob4 = 'F';
if (hobies.Contains('1')) hob1 = 'T';
if (hobies.Contains('2')) hob2 = 'T';
if (hobies.Contains('3')) hob3 = 'T';
if (hobies.Contains('4')) hob4 = 'T';
int yborn = int.Parse(yearBorn);
int prefix = int.Parse(Request.Form["prefix"]);
int phone = int.Parse(Request.Form["phone"]);
tableByform += "<table>";
tableByform += "<tr><td> username:</td><td>" + uname + "</td></tr>";
tableByform += "<tr><td> first name:</td><td>" + Fname + "</td></tr>";
tableByform += "<tr><td> last name:</td><td>" + lname + "</td></tr>";
tableByform += "<tr><td> email:</td><td>" + email + "</td></tr>";
tableByform += "<tr><td> gender:</td><td>" + gender + "</td></tr>";
tableByform += "<tr><td> YearBorn:</td><td>" + yearBorn + "</td></tr>";
tableByform += "<tr><td> City:</td><td>" + City + "</td></tr>";
tableByform += "<tr><td> prefix:</td><td>" + prefix + "</td></tr>";
tableByform += "<tr><td> phone:</td><td>" + phone + "</td></tr>";
tableByform += "<tr><td> hobies</td><td>" + hobies + "</td><td>";
if (hob1== 'T')
{
tableByform += "singing,";
}
if (hob2 == 'T')
{
tableByform += "playing,";
}
if (hob3 == 'T')
{
tableByform += "swimming,";
}
if (hob4 == 'T')
{
tableByform += "eating,";
}
tableByform += "</td></tr>";
tableByform += "<tr><td> Password:</td><td>" + Password + "</td></tr>";
tableByform += "<tr><td> verify password:</td><td>" + verify_password + "</td></tr>";
tableByform += "</table>";
string sqlSelect = $"SELECT * FROM {tableName} WHERE uname= '{uname}'";
if (Helper.IsExist(fileName,sqlSelect))
{
st= "this user is taken";
sqlmsg = sqlSelect;
}
else
{
string sqlInsert = $"insert into {tableName}";
sqlInsert += $"values('{uname}', N'{Fname}', N'{lname}', ";
sqlInsert += $"'{email}', {yearBorn}, '{gender}', '{prefix}', '{phone}', ";
sqlInsert += $"N'{City}', '{hob1}, '{hob2}', '{hob3}','{hob4}','{Password}')";
sqlmsg = sqlInsert;
Helper.DoQuery(fileName, sqlInsert);
msg = "Succsses";
}
}
}
}
}`