我對這個Web應用程序的東西有點新。當我在ASP.NET Web Forms Application的Visual Studios 2012中創建一個新項目時,它會生成多個預定義的頁面/函數。我真的想要使用這些功能,因爲它看起來好像可以節省我一些時間。從DefaultConnection數據庫獲取已登錄/用戶名登錄VB.net 2012 ASP.NET Web窗體應用程序
在這一點上,我注意到它有一個Register.aspx和Login.aspx,它工作正常。 問題是,我在Access 2007中的數據庫中有一些表。我想知道是否有可能執行以下操作之一以及如何執行以下操作之一:
1)保留DefualtConnection數據庫並查詢當前登錄的用戶名,然後使用該用戶名來查詢我的Access數據庫以獲取基於信息的信息在那個用戶名上。
2)創建我自己的註冊並使用Access數據庫登錄。我想知道如何跟蹤這個案例的登錄用戶,並且在使用創建用戶嚮導時我也會遇到錯誤
請幫助,我需要這些信息,以便我可以繼續在我的最終項目上工作。教授不知道如何做到這一點,我一直在尋找網絡和答案,但似乎我可能沒有提出正確的問題。感謝提前:)
*編輯
•我的意思是通過登錄的用戶: 圖片https://dl.dropbox.com/u/22962879/Project_4_Registro_Est/Logged%20in%20user%20Project4.png
•DefaulConnection:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Project_4_Registro_Est-20130131171154;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Project_4_Registro_Est-20130131171154.mdf"
providerName="System.Data.SqlClient" />
•我的Access數據庫
myConn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\cast\Documents\test.accdb")
我的解決方案:
事實證明,我可以通過調用User.Identity.Name獲取登錄的用戶名。 所以我做了以下內容:
'//The following code is an example of using the Logged/signed in username to then'
'//Query other Databases based on the user name:'
Dim myConn As System.Data.OleDb.OleDbConnection
Dim cmd As New System.Data.OleDb.OleDbCommand
Dim sqlstring As String
'//Connecting to My Database:'
myConn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\cast\Documents\test.accdb")
'//Query I wish to use to find all data based on User name:'
sqlstring = "Select FirstName, LastName, UserType FROM users WHERE Username = '" + User.Identity.Name + "'"
Try
'//Start by opening the connection'
myConn.Open()
'//I use str for now to store the results'
Dim str As String = ""
'//Set the command by adding the SQL string and Connection:'
cmd = New OleDb.OleDbCommand(sqlstring, myConn)
'//Create variable which contains results from Executed command:'
Dim oledbReader As OleDb.OleDbDataReader = cmd.ExecuteReader
'//Keep reading each row that contains the Queried Results:'
While oledbReader.Read
'//Store result to str. each item is a Column in the order I Queried'
str = str + (oledbReader.Item(0) & " " & oledbReader.Item(1) & " (" & oledbReader.Item(2)).ToString() & ")" + "\n"
End While
'//Show results on page's Label1:'
Label1.Text = str
'//Close everything'
oledbReader.Close()
cmd.Dispose()
myConn.Close()
Catch ex As Exception
'//show error message if could not connect'
MsgBox("Can not open connection! X_X")
End Try
請發佈一個連接字符串和一些筆記,說明你的意思是登錄用戶。 – Fionnuala 2013-02-08 15:28:01
我添加了更多信息... – Gabriel 2013-02-08 17:01:53
這不是MS Access,即SQL Server,本地數據庫,AFAICT。 – Fionnuala 2013-02-08 17:07:58