Quantcast
Channel: DataSource Controls - SqlDataSource, ObjectDataSource, etc.
Viewing all articles
Browse latest Browse all 956

Asp.net/Vb.net - How can i store the user's reference to database?

$
0
0

I want to store the reference of customers to database , and when they login , they can view their own reference . but some how i still got some troubles , can you have a look ? and show me the solution , thanks in advance.


Table aspnet_User



Table Userinfo , its a FK of table aspnet_User

Here is my code :
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString2").ToString())
conn.Open()

'Customer Reference

Dim chars As String = "1234ABCD"
Dim orderref As String = ""
Dim r As New Random()
Dim i As Integer
For i = 1 To 8
orderref += chars.Substring(r.Next(chars.Length), 1)
Next
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString2").ConnectionString
Dim insertSql As String = "INSERT INTO Userinfo(UserId,HomeTown,HomePage,Orderref) VALUES(@UserId,@HomeTown,@HomePage,@Orderref)"
Using myConnection As New SqlConnection(connectionString)
myConnection.Open()
Dim myCommand As New SqlCommand(insertSql, myConnection)
'myCommand.Parameters.AddWithValue("@UserId", DBNull.Value)
myCommand.Parameters.AddWithValue("@HomeTown", DBNull.Value)
myCommand.Parameters.AddWithValue("@HomePage", DBNull.Value)
myCommand.Parameters.AddWithValue("@Orderref", orderref)

myCommand.ExecuteNonQuery()
myConnection.Close()
End Using


Viewing all articles
Browse latest Browse all 956

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>