mdb在创建新行时设置空单元格默认值
本文关键字:单元格 默认值 设置 新行时 创建 mdb | 更新日期: 2023-09-27 18:19:12
我还有一个问题想问愿意帮忙的人。这应该是相当容易的,但无论出于什么原因,我似乎不能得到它的权利。我正在用visual studio 08在c#中创建一个asp.net网站
我试图有一个用户注册,这一切都工作得很好,并有新的用户默认为用户,而不是管理员。我使用。mdb作为存储一切的地方。
是否可以在我的初始SQL查询中做到这一点?目前我的代码看起来像
strSQL = "Insert into tblUserLogin " +
"(UserFirstName, UserLastName, UserName, UserPassword, UserAddress, UserCity, UserState, UserZipCode, UserEmail, UserPhone, ) values ('" +
UserFirstName + "', '" + UserLastName + "', '" + UserName + "', '" + UserPassword + "', '" + UserAddress +
"', '" + UserCity + "', '" + UserState + "', '" + UserZipCode + "', '" + UserEmail + "', '" + UserPhone +
"')";
// set the command text of the command object
command.CommandType = CommandType.Text;
command.CommandText = strSQL;
// Execute the insert statement
command.ExecuteNonQuery();
这将成功地将所有内容发布到. mdb,并且它将使列SecurityLevel下的单元格为空。
i trying to add
"(UserFirstName, UserLastName, UserName, UserPassword, UserAddress, UserCity, UserState, UserZipCode, UserEmail, UserPhone, SecurityLevel=U )
,但这并没有像我希望的那样工作。是否有一种简单的方法可以使该值SecurityLevel默认为U,而无需任何人指定它?
感谢您的宝贵时间
如果我理解正确,请使用SecurityLevel
列的const值'U'
strSQL = "INSERT INTO tblUserLogin " +
"(UserFirstName, UserLastName, " +
" UserName, UserPassword, " +
" UserAddress, UserCity, " +
" UserState, UserZipCode, " +
" UserEmail, UserPhone, SecurityLevel) " +
"VALUES (" +
UserFirstName + "', '" + UserLastName + "', '" +
UserName + "', '" + UserPassword + "', '" +
UserAddress + "', '" + UserCity + "', '" +
UserState + "', '" + UserZipCode + "', '" +
UserEmail + "', '" + UserPhone + "', 'U')"; // pass a const value for SecurityLevel column
// the rest of your code goes here
附带说明:您的代码很容易受到sql注入的攻击。学习和使用准备好的(参数化的)语句,而不是动态地构建查询字符串。