錯誤顯示爲「附近有語法錯誤@Cmp_DocPath',如果我使用註釋行代碼中,我得到了錯誤的‘與參數名稱的SqlParameter的‘@Cmp_DocPath’不受此sqlparametercollection載’。怎麼我獲得文件名AsyncFileUpload AJAX控制的?不正確的語法時,通參數
protected void BtnCmpApproval_Click(object sender, EventArgs e)
{
SqlConnection SqlCon = new SqlConnection(GetConnectionString());
string query = "INSERT INTO User_Info2 VALUES (@lblCmpUserName,@txtCmpName,
@txtRegCountry,@txtCmpRegNo,@txtCmpEstdate,@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["@Cmp_DocPath"].Value=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();
}
}
感謝all.Now我加了參數Cmp_DocPath.Now新的錯誤被顯示爲「必須聲明標量變量」@lblCmpUserName「」我使用的是Visual Studio 2010和sql server 2008 – Hari
@Hari,是的,看看代碼,在你的查詢中你有一個名爲'@ lblCmpUserName'的東西,然而,你只需將其命名爲'@ UserName'。這些名稱必須匹配。 –
http://stackoverflow.com/questions/11062491/must-declare-the-scalar-variable-lblcmpusername – Hari