-4
這裏是新手。需要一些建議。我想在數據庫中插入值,並且代碼中沒有錯誤。我無法弄清楚這個問題,爲什麼它不能值插入數據庫如何在數據庫中插入值
這裏我的代碼
string Constr = @"Data Source=(local);Integrated Security=True;Database=DDLYBank";
SqlConnection Conn = new SqlConnection(Constr);
string MainAccInfo = "Select AccountNo, HashValue from MainAcc Where HashValue = '" + ccinfo + "'";
SqlCommand cmd1 = new SqlCommand(MainAccInfo, Conn);
SqlDataReader read1 = cmd1.ExecuteReader();
using (SqlCommand command = Conn.CreateCommand())
{
command.CommandText = "Insert INTO Record (AccountNo, HashValue, Debit, Balance, Date_Time, FingerPrint) Values (@AccountNo, @HashValue, @Debit, @Balance, @Date_Time, @FingerPrint)";
command.Parameters.AddWithValue("@AccountNo", read1["AccountNo"]);
command.Parameters.AddWithValue("@HashValue", read1["HashValue"]);
command.Parameters.AddWithValue("@Debit", rDebit);
command.Parameters.AddWithValue("@Balance", aBalance);
command.Parameters.AddWithValue("@Date_Time", rDate);
command.Parameters.AddWithValue("@FingerPrint", rFingerPrint);
Conn.Open();
command.ExecuteNonQuery();
}
}
catch (SqlException ex)
{
return;
}
你缺少的@符號在SQL命令的參數名稱的前面。 –
你的意思是? 「@AccountNo」 我已經嘗試過。還是不能,我會做。 –
你有例外嗎? – Jodrell