基本上我在做一個系統,用戶輸入名稱,電子郵件,密碼&用戶類型和這些輸入要保存到我的本地數據庫。 我想創建一個自動生成並遞增ID的主鍵ID,所以第一個輸入1,秒2,三等獎3項,等等Mysql主鍵ID問題
相反,我得到了一堆字母和隨機數等如下所示; d7a8675a-c7cf-406A-983f-370d5b96fa62
下面是我寫上的Visual Studio數據庫設計
CREATE TABLE [dbo].[Users] (
[Id] int IDENTITY(1,1) PRIMARY KEY,
[UserName] NCHAR (50) NULL,
[Email] NCHAR (50) NULL,
[Password] NCHAR (50) NULL,
[Role] NCHAR (15) NULL
);
此外,我忘了提,當我訪問我的註冊。 aspx頁面,用戶可以填寫要插入到數據庫的字段,我在註冊按鈕上點擊以下內容,是否可能導致我的SQL代碼出現問題?
String insertQuery = "insert into Users (Id,UserName,Email,Password,Role) values (@Id ,@Uname ,@email ,@password ,@role)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@Id", newGUID.ToString());
com.Parameters.AddWithValue("@Uname",TextBoxUN.Text);
com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
com.Parameters.AddWithValue("@password", TextBoxPass.Text);
com.Parameters.AddWithValue("@role", DropDownListRole.SelectedItem.ToString());
如何保存數據,顯示整個代碼 – lad2025
另外我忘了提及,當我訪問我的Register.aspx頁面,其中用戶可以填寫要插入到數據庫中的字段我打電話給以下點擊Register按鈕,是否會導致我的SQL代碼出現問題? –
所以你保存GUID'com.Parameters.AddWithValue(「@Id」,newGUID.ToString());'。跳過這一行,並允許工作'IDENTITY' – lad2025