asp.net 4.0 で新しい Web ページを作成するときに提供されるデフォルトの ASPNETDB.MDF データベースに追加したテーブルにアクセスする方法はありますか。5 つの列を持つBuilderTableというテーブルを追加しました。また、IDを独自にインクリメントする必要があります。is identity オプションを yes に設定し、id のインクリメントを 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);