我晕 你还没结贴? 今天看了下 随便写了个小示例 你看看 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Windows { public partial class Execution : Form {
1.定义个ArrayList,里面存储的数据结构为:
航班号,起飞城市,抵达城市。
2.在Combobox的Selectchanged函数中取得Combobox的数值,然后去ArrayList中查找
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Windows
{
public partial class Execution : Form
{
public Execution()
{
InitializeComponent();
}
SqlConnection conn = Sqlconn.Sqlconnec();
private void Execution_Load(object sender, EventArgs e)
{
SqlDataAdapter dape = new SqlDataAdapter("select * from 公交司机反馈信息", conn);
DataSet ds = new DataSet();
dape.Fill(ds);
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "username";
label3.DataBindings.Add("Text", ds.Tables[0], "Driver");
label4.DataBindings.Add("Text", ds.Tables[0], "Driver1");
label5.DataBindings.Add("Text", ds.Tables[0], "Driver2");
label6.DataBindings.Add("Text", ds.Tables[0], "Driver3");
label7.DataBindings.Add("Text", ds.Tables[0], "Driver4");
label8.DataBindings.Add("Text", ds.Tables[0], "Driver5");
label12.DataBindings.Add("Text", ds.Tables[0], "Driver6");
label10.DataBindings.Add("Text", ds.Tables[0], "CirSuggestions1");
} private void button1_Click(object sender, EventArgs e)
{
object username = ((System.Data.DataRowView)comboBox1.SelectedItem)["username"];
string str = textBox1.Text;
string str1 = label3.Text;
string str2 = label4.Text;
string str3 = label5.Text;
string str4 = label6.Text;
string str5 = label7.Text;
string str6 = label8.Text;
string str7 = label12.Text;
string str8 = label10.Text;
if (textBox1.Text == "")
{
MessageBox.Show("请写上回应", "信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
SqlCommand cmm = new SqlCommand("select * from Execution where username=@username", conn);
cmm.Parameters.AddWithValue("username", username);
SqlDataAdapter dape = new SqlDataAdapter(cmm);
DataSet ds=new DataSet();
int n=dape.Fill(ds);
if (n > 0)
{
MessageBox.Show("此条信息你已处决", "信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox1.Text = "";
}
else
{
SqlCommand cmd = new SqlCommand("insert into Execution(username,Driver,Driver1,Driver2,Driver3,Driver4,Driver5,Driver6,CirSuggestions1,executionIm) values(@username,@Driver,@Driver1,@Driver2,@Driver3,@Driver4,@Driver5,@Driver6,@CirSuggestions1,@executionIm)", conn);
conn.Open();
cmd.Parameters.AddWithValue("username", username);
cmd.Parameters.AddWithValue("Driver", str1);
cmd.Parameters.AddWithValue("Driver1", str2);
cmd.Parameters.AddWithValue("Driver2", str3);
cmd.Parameters.AddWithValue("Driver3", str4);
cmd.Parameters.AddWithValue("Driver4", str5);
cmd.Parameters.AddWithValue("Driver5", str6);
cmd.Parameters.AddWithValue("Driver6", str7);
cmd.Parameters.AddWithValue("CirSuggestions1", str8);
cmd.Parameters.AddWithValue("executionIm", str);
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
MessageBox.Show("信息处决成功", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Text = "";
}
}
起飞城市和抵达城市都包装到一个类里面,比如说包装为Flightshedule类,然后以航班号作为键,
将Flightshedul类的对象作为值,这样你选择comBox的内容就好一一对应了!