【发布时间】:2015-04-17 09:58:43
【问题描述】:
数据库表:注册和购买 (使用 1-10000 范围内的唯一 ID 作为主键和外键连接两个表)
当有相应ID的游客进行在线购买时,如何在我的购买表中添加唯一ID?
我正在使用 Visual Studio 开发 asp.net。但是,如何存储客户端的唯一 ID 以识别他们的日志记录活动?
string result = "0";
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sim\Desktop\Web.accdb";
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "select ID from Registration where Name ='" + TextBox1.Text + "' and Password ='" + TextBox2.Text + "'";
string getValue = command.ExecuteScalar().ToString();
if (getValue != null)
{
result = getValue.ToString();
}
Session.Add("UserID", result);
command.CommandText = "select * from Registration where Name ='" + TextBox1.Text + "' and Password ='" + TextBox2.Text + "'";
OleDbDataReader reader = command.ExecuteReader();
int count = 0;
while (reader.Read())
{
count = count + 1;
}
if (String.IsNullOrEmpty(TextBox1.Text))
{
MessageBox.Show("You have't input the Username.");
}
if (String.IsNullOrEmpty(TextBox2.Text))
{
MessageBox.Show("you havn't input the Password.");
}
if (count == 1)
{
MessageBox.Show("Username and password is valid");
connection.Close();
connection.Dispose();
Response.Redirect("Loginpage.aspx", true);
}
else
{
MessageBox.Show("Username or Password is not matched");
}
}
【问题讨论】:
-
客户活动是什么意思?
-
我想保存客户对应的唯一ID,以便在客户进行网上购物活动时,我可以穿上唯一ID
-
使用
Process.GetCurrentProcess().SessionId获取会话 ID,这对于每个用户的每个会话都是唯一的。 -
在登录页面使用???然后我如何将相应的唯一 ID 标记到采购表中>
-
是的,这将一直存在到用户结束其会话。因此,如果用户有一个唯一 ID,并且他将购买任何产品,您可以将该 ID 与购买表绑定
标签: asp.net sql-server c#-4.0 relational-database primary-key