当用户使用他的登录时UserName
,我将UserName
如下代码发送到下一页Page_Load
lblCmpUserName.Text = Server.UrlDecode(Request.QueryString["Parameter"].ToString());
然后我想将带有用户名的“公司详细信息”存储在 SQL Server 2008 表中。
我得到了错误
必须声明标量变量“@lblCmpUserName”
代码:
protected void BtnCmpApproval_Click(object sender, EventArgs e)
{
SqlConnection SqlCon = new SqlConnection(GetConnectionString());
string query = "INSERT INTO Company_Info2 VALUES (@lblCmpUserName, @txtCmpName, @txtRegCountry, @txtCmpRegNo, @txtCmpEstdate,@AFU1, @txtCmpAddress, @ddlAddrIn)";
try
{
SqlCon.Open();
SqlCommand cmd = new SqlCommand(query, SqlCon);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@UserName", lblCmpUserName.Text);
cmd.Parameters.AddWithValue("@Cmp_Name", txtCmpName.Text);
cmd.Parameters.AddWithValue("@Commercial_RegNo", txtRegCountry.Text);
cmd.Parameters.AddWithValue("@Comm_Country", txtCmpRegNo.Text);
cmd.Parameters.AddWithValue("@Cmp_EstablishDate", txtCmpEstdate.Text);
cmd.Parameters.AddWithValue("@Cmp_DocPath", AFU1.FileName);
cmd.Parameters.AddWithValue("@txtCmpAddress", txtCmpAddress.Text);
cmd.Parameters.AddWithValue("@ddlAddrIn", ddlAddrIn.SelectedItem.Text);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
SqlCon.Close();
}
}