新手来了 需要一些建议。我想将值插入数据库,到目前为止代码中没有错误。我无法弄清楚为什么它无法将值插入数据库的问题
这是我的代码
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;
}