Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net ASP服务器变量登录用户_Asp.net_Insert_Insert Into - Fatal编程技术网

Asp.net ASP服务器变量登录用户

Asp.net ASP服务器变量登录用户,asp.net,insert,insert-into,Asp.net,Insert,Insert Into,在我的代码背后,我有这个 { Label2.Text = "[" + HttpContext.Current.User.Identity.Name + "]"; } 标识域中的用户名。到现在为止,一直都还不错。它在IIS中正常工作 但是,我想将用户名存储到数据库中。我该怎么做 这样做的目的是记录回答这个问题的人: string insertCmd = "INSERT INTO worker(Business,Business2,Mobile) VALUES (@Business,@B

在我的代码背后,我有这个

{
    Label2.Text = "[" + HttpContext.Current.User.Identity.Name + "]"; 
}
标识域中的用户名。到现在为止,一直都还不错。它在IIS中正常工作

但是,我想将用户名存储到数据库中。我该怎么做

这样做的目的是记录回答这个问题的人:

string insertCmd = "INSERT INTO worker(Business,Business2,Mobile) VALUES (@Business,@Business2,@Mobile)";
using (Conn)
{
    Conn.Open();
    OleDbCommand myCommand = new OleDbCommand(insertCmd, Conn);
    myCommand.Parameters.AddWithValue("@Business", business.Text);
    myCommand.Parameters.AddWithValue("@Business2", business2.Text);
    myCommand.Parameters.AddWithValue("@Mobile", mobile.Text);
    myCommand.ExecuteNonQuery();
    Label1.Text = "Saved Successfull!";
    Label1.ForeColor = System.Drawing.Color.Green;
}

我已将答案插入数据库,但如何保存回答者?我可以将标签保存到数据库表中吗?还是不可能呢?

只需在表中添加一个
用户名
字段,然后添加另一个参数:

string insertCmd = "INSERT INTO worker(Business,Business2,Mobile,username) VALUES (@Business,@Business2,@Mobile,@username)"; 

using (Conn) { 
  Conn.Open(); 
  OleDbCommand myCommand = new OleDbCommand(insertCmd, Conn); 
  myCommand.Parameters.AddWithValue("@Business", business.Text); 
  myCommand.Parameters.AddWithValue("@Business2", business2.Text); 
  myCommand.Parameters.AddWithValue("@Mobile", mobile.Text); 
  myCommand.Parameters.AddWithValue("@username", HttpContext.Current.User.Identity.Name); 
  myCommand.ExecuteNonQuery(); 

  Label1.Text = "Saved Successfull!"; 
  Label1.ForeColor = System.Drawing.Color.Green; 

}

我添加它,但给我错误。用户代码未处理OLEDBEException。插入到“我的坏!问题是数据库…(noob)谢谢!你能帮我一次吗@Peter Hahndorf也许你能再帮我一次。如何读取数据库?如果用户名存在,则显示该特定用户名中的行,如果不存在,则插入到