2013-06-20 15 views
0

的空單元格默認我對任何人都願意幫助另一個問題。這應該是相當容易的,但無論出於什麼原因,我似乎都無法做到。林與Visual Studio 08在C#創建一個asp.net網站。MDB設置上創造新行

即時通訊試圖有一個用戶註冊,這是所有工作的偉大工作,並有新的用戶默認爲用戶而不是管理。我正在使用.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空。

我試圖添加

"(UserFirstName, UserLastName, UserName, UserPassword, UserAddress, UserCity, UserState, UserZipCode, UserEmail, UserPhone, SecurityLevel=U) 

,但正如我希望的那樣並沒有工作。有一個簡單的辦法有一個價值SECURITYLEVEL默認至U,而無需指定它的人?

感謝您的時間

回答

0

如果我理解你正確地只使用一個常量的值'U'SecurityLevel

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的注射。學習並使用準備好的(參數化)語句,而不是動態構建查詢字符串。

+0

謝謝你,偉大的工作。一切正常發佈,並且安全級別是一個常數U.再次感謝! –