做了个航班管理系统 增删都成功
就是修改航班信息的时候 数据库和表的内容都没有修改保持原样 没有任何语法错误
//更改数据库
public int editFlight(FlightInfo flight)
{
int re = -1;
Database db = new Database();
db.getConn();
string sql = "select * from flightInfo where f_flight = '" + flight.getF_flight()+"'";
DataTable dt = db.query(sql);
sql = "update flightInfo set f_ecoprice = '" + flight.getF_ecoprice() + "'";
sql += ", f_company = '" + flight.getF_company() + "'";
sql += ", f_airmodel = '" + flight.getF_airmodel() + "'";
sql += ", f_departure = '" + flight.getF_departure() + "'";
sql += ", f_destination = '" + flight.getF_destination() + "'";
sql += ", f_start= '" + flight.getF_start() + "'";
sql += ", f_arrival= '" + flight.getF_arrival() + "'";
sql += ", f_topseat = '" + flight.getF_topseat() + "'";
sql += ", f_topprice= '" + flight.getF_topprice() + "' ";
sql += ", f_ecoseat= '" + flight.getF_ecoseat() + "' ";
sql += ", f_flight ='" + flight.getF_flight() + "' ";
sql += "where f_flight ='"+ flight.getF_flight() +"'"; re = db.update(sql);
db.closeConn();
return re;
} public int update(string sql)
{
int re = -1;
SqlCommand command = new SqlCommand();
command.Connection = conn;
command.CommandText = sql;
re = command.ExecuteNonQuery();
this.closeConn();
return re;
}//按确定按钮 提交修改后的信息
private void button1_Click(object sender, EventArgs e)
{
string f_flight;
f_flight = this.oldtxtF_flight.Text;
FlightInfoBussiness uib = new FlightInfoBussiness();
FlightInfo flight = uib.getFlight(f_flight);
flight.setF_flight(this.newtxtF_flight.Text);
flight.setF_company(this.newtxtF_company.Text);
flight.setF_airmodel(this.newtxtF_airmodel.Text);
flight.setF_departure(this.newtxtF_departure.Text);
flight.setF_destination(this.newtxtF_destination.Text);
flight.setF_start(this.newtxtF_start.Text);
flight.setF_arrival(this.newtxtF_arrival.Text);
flight.setF_topseat(int.Parse(this.newtxtF_topseat.Text));
flight.setF_topprice(float.Parse(this.newtxtF_topprice.Text));
flight.setF_ecoseat(int.Parse(this.newtxtF_ecoseat.Text));
flight.setF_ecoprice(float.Parse(this.newtxtF_ecoprice.Text));
int re = uib.editFlight(flight);
if (re > -1)
{
MessageBox.Show("航班信息已修改!");
f3.dataGridView1.DataSource = uib.getAllFlight();
f3.dataGridView1.Refresh();
this.Close();
}
else
{
MessageBox.Show("修改失败");
}
}我已经改了很久了 希望各位帮帮忙
就是修改航班信息的时候 数据库和表的内容都没有修改保持原样 没有任何语法错误
//更改数据库
public int editFlight(FlightInfo flight)
{
int re = -1;
Database db = new Database();
db.getConn();
string sql = "select * from flightInfo where f_flight = '" + flight.getF_flight()+"'";
DataTable dt = db.query(sql);
sql = "update flightInfo set f_ecoprice = '" + flight.getF_ecoprice() + "'";
sql += ", f_company = '" + flight.getF_company() + "'";
sql += ", f_airmodel = '" + flight.getF_airmodel() + "'";
sql += ", f_departure = '" + flight.getF_departure() + "'";
sql += ", f_destination = '" + flight.getF_destination() + "'";
sql += ", f_start= '" + flight.getF_start() + "'";
sql += ", f_arrival= '" + flight.getF_arrival() + "'";
sql += ", f_topseat = '" + flight.getF_topseat() + "'";
sql += ", f_topprice= '" + flight.getF_topprice() + "' ";
sql += ", f_ecoseat= '" + flight.getF_ecoseat() + "' ";
sql += ", f_flight ='" + flight.getF_flight() + "' ";
sql += "where f_flight ='"+ flight.getF_flight() +"'"; re = db.update(sql);
db.closeConn();
return re;
} public int update(string sql)
{
int re = -1;
SqlCommand command = new SqlCommand();
command.Connection = conn;
command.CommandText = sql;
re = command.ExecuteNonQuery();
this.closeConn();
return re;
}//按确定按钮 提交修改后的信息
private void button1_Click(object sender, EventArgs e)
{
string f_flight;
f_flight = this.oldtxtF_flight.Text;
FlightInfoBussiness uib = new FlightInfoBussiness();
FlightInfo flight = uib.getFlight(f_flight);
flight.setF_flight(this.newtxtF_flight.Text);
flight.setF_company(this.newtxtF_company.Text);
flight.setF_airmodel(this.newtxtF_airmodel.Text);
flight.setF_departure(this.newtxtF_departure.Text);
flight.setF_destination(this.newtxtF_destination.Text);
flight.setF_start(this.newtxtF_start.Text);
flight.setF_arrival(this.newtxtF_arrival.Text);
flight.setF_topseat(int.Parse(this.newtxtF_topseat.Text));
flight.setF_topprice(float.Parse(this.newtxtF_topprice.Text));
flight.setF_ecoseat(int.Parse(this.newtxtF_ecoseat.Text));
flight.setF_ecoprice(float.Parse(this.newtxtF_ecoprice.Text));
int re = uib.editFlight(flight);
if (re > -1)
{
MessageBox.Show("航班信息已修改!");
f3.dataGridView1.DataSource = uib.getAllFlight();
f3.dataGridView1.Refresh();
this.Close();
}
else
{
MessageBox.Show("修改失败");
}
}我已经改了很久了 希望各位帮帮忙
SET f_ecoprice = '8', f_company = '8', f_airmodel = '8', f_departure = '8',
f_destination = '8', f_start = '8', f_arrival = '8', f_topseat = 8, f_topprice = 8,
f_ecoseat = 8, f_flight = '8'
WHERE (f_flight = '1') 是正确的可以修改的