我正在尝试从 Customer 表中检索“customer_id”并将其插入
fare_tariff(tariff_id, customer_id, total_price)
所以我从 Customer 表中检索 customer_id,如下所示:
using (SqlCommand command = new SqlCommand("SELECT customer_id FROM Customer WHERE UserName = '" + username + "' Password = '"+password +"' ", connection))
{
string cust_id = customer_id.ToString();
SqlDataReader myReader = command.ExecuteReader();
if (myReader.Read())
{
cust_id = myReader["customer_id"].ToString();
}
int c_id = Convert.ToInt32(cust_id);
myReader.Close();
custID(c_id);
}
并将 customer_id 插入到 fare_tariff 表中,如下所示:
using (SqlCommand command = new SqlCommand("INSERT INTO flight_reservation(tariff_id, customer_id, total_price) VALUES(@val1,@val2,@val3)", connection))
{
command.Parameters.Add("@val1", SqlDbType.Int).Value = tariff_id;
command.Parameters.Add("@val2", SqlDbType.Int).Value = customer_id;
command.Parameters.Add("@val3", SqlDbType.VarChar).Value = total_price.ToString();
command.ExecuteNonQuery();
}
我将customer_id 声明为用于存储customer_id 的变量。
问题是:关税 ID 和总价格已成功插入,但客户 ID 列仍为空。
需要帮助。