有没有办法访问我添加到默认 ASPNETDB.MDF 数据库中的表,当您在 asp.net 4.0 中创建新网页时提供给您。我添加了一个名为BuilderTable的表,它有 5 列。我还需要它自己增加 ID。我已将 is identity 选项设置为 yes 并将身份增量设置为 1,因此如何在不向其后面的代码中的 ID 列发送值的情况下使其工作。这是c#中的代码:(我在switch语句中有它,所以不要介意案例1)
case "1":
if (Roles.IsUserInRole(usr.UserName, "Builder") == false)//if the user is not already in the builder role then add them
{
Roles.AddUserToRole(usr.UserName, "Builder");//here we add the user into the builder role
string connection = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlConnection conn = null;
conn = new SqlConnection(connection);
conn.Open();
using (SqlCommand cmd = new SqlCommand())
{
int nothing = 0;
string query = String.Format("INSERT INTO 'BuilderTable' VALUES('{0}', '{1}', '{2}', '{3}', '{4}')", nothing, p.fName, p.lName, p.Address, usr.Email);
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
}
break;
此代码导致错误:
“BuilderTable”附近的语法不正确
提前致谢!
编辑 认为我应该澄清我在代码的其他地方声明了这个
string userName = Request.QueryString["user"];
MembershipUser usr = Membership.GetUser(userName);
ProfileCommon p = Profile.GetProfile(usr.UserName);