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.OleDb;
using System.IO;namespace 车库管理系统
{
public partial class Form1 : Form
{
private DataSet dsnew;
private OleDbCommand command = new OleDbCommand();
private OleDbConnection connection;
private OleDbDataAdapter adapter;
private DataTable thetable = new DataTable();
public Form1()
{
InitializeComponent();
}
public int a = 0; private void 信息BindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.信息BindingSource.EndEdit();
this.信息TableAdapter.Update(this.userDataSet.信息); }
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“userDataSet.信息”中。您可以根据需要移动或移除它。
this.信息TableAdapter.Fill(this.userDataSet.信息);
} private void pictureBox1_Click(object sender, EventArgs e)
{
this.textBox8.Text = "请输入停车卡号关键字";
this.textBox8.Focus();
textBox8.SelectAll();
a = 1; }
private void pictureBox2_Click(object sender, EventArgs e)
{
this.textBox8.Text = "请输入车主姓名关键字";
a = 2;
this.textBox8.Focus();
textBox8.SelectAll(); }
private void pictureBox5_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(); //返回
f2.Show();
this.Hide();
} private void button2_Click(object sender, EventArgs e)
{
if (a == 0)
{
MessageBox.Show("请选择查询条件!");
textBox8.Focus();
textBox8.SelectAll();
}
if (a == 1)
{
string con = "Select * from 信息 where 停车卡号 like '%" + textBox8.Text + "%'";
connection = new OleDbConnection();
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\车库管理系统\\user.mdb";
connection.Open();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = con;
adapter = new OleDbDataAdapter("Select * From 信息", connection);
adapter.SelectCommand = command;
dsnew = new DataSet();
adapter.Fill(dsnew, "user");
thetable = dsnew.Tables["user"];
信息DataGridView.DataSource = thetable;
}
if (a == 2)
{
string con = "Select * from 信息 where 车主姓名 like '%" + textBox8.Text + "%'";
connection = new OleDbConnection();
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\车库管理系统\\user.mdb";
connection.Open();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = con;
adapter = new OleDbDataAdapter("Select * From 信息", connection);
adapter.SelectCommand = command;
dsnew = new DataSet();
adapter.Fill(dsnew, "user");
thetable = dsnew.Tables["user"];
信息DataGridView.DataSource = thetable;
}
} private void button3_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
f1.Show();
this.Hide();
} private void button4_Click(object sender, EventArgs e)
{
if (MessageBox.Show("你确定删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
信息DataGridView.Rows.RemoveAt(信息DataGridView.SelectedRows[0].Index);
else
{
Form1 f1 = new Form1();
f1.Show();
this.Hide();
}
} private void 信息DataGridView_CurrentCellChanged(object sender, EventArgs e)
{
//信息DataGridView内容显示到textbox里,可是加入这个事件之后,进行查询、删除的操作就无法调试通过了,提示(this.textBox2.Text = this.信息DataGridView.CurrentRow.Cells[0].Value.ToString(); “未将对 象引用设置到对象的实例”。) this.textBox2.Text = this.信息DataGridView.CurrentRow.Cells[0].Value.ToString();
this.textBox3.Text = this.信息DataGridView.CurrentRow.Cells[1].Value.ToString();
this.textBox4.Text = this.信息DataGridView.CurrentRow.Cells[2].Value.ToString();
this.textBox5.Text = this.信息DataGridView.CurrentRow.Cells[3].Value.ToString();
this.textBox6.Text = this.信息DataGridView.CurrentRow.Cells[4].Value.ToString();
this.textBox7.Text = this.信息DataGridView.CurrentRow.Cells[5].Value.ToString();
} }
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;namespace 车库管理系统
{
public partial class Form1 : Form
{
private DataSet dsnew;
private OleDbCommand command = new OleDbCommand();
private OleDbConnection connection;
private OleDbDataAdapter adapter;
private DataTable thetable = new DataTable();
public Form1()
{
InitializeComponent();
}
public int a = 0; private void 信息BindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.信息BindingSource.EndEdit();
this.信息TableAdapter.Update(this.userDataSet.信息); }
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“userDataSet.信息”中。您可以根据需要移动或移除它。
this.信息TableAdapter.Fill(this.userDataSet.信息);
} private void pictureBox1_Click(object sender, EventArgs e)
{
this.textBox8.Text = "请输入停车卡号关键字";
this.textBox8.Focus();
textBox8.SelectAll();
a = 1; }
private void pictureBox2_Click(object sender, EventArgs e)
{
this.textBox8.Text = "请输入车主姓名关键字";
a = 2;
this.textBox8.Focus();
textBox8.SelectAll(); }
private void pictureBox5_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(); //返回
f2.Show();
this.Hide();
} private void button2_Click(object sender, EventArgs e)
{
if (a == 0)
{
MessageBox.Show("请选择查询条件!");
textBox8.Focus();
textBox8.SelectAll();
}
if (a == 1)
{
string con = "Select * from 信息 where 停车卡号 like '%" + textBox8.Text + "%'";
connection = new OleDbConnection();
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\车库管理系统\\user.mdb";
connection.Open();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = con;
adapter = new OleDbDataAdapter("Select * From 信息", connection);
adapter.SelectCommand = command;
dsnew = new DataSet();
adapter.Fill(dsnew, "user");
thetable = dsnew.Tables["user"];
信息DataGridView.DataSource = thetable;
}
if (a == 2)
{
string con = "Select * from 信息 where 车主姓名 like '%" + textBox8.Text + "%'";
connection = new OleDbConnection();
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\车库管理系统\\user.mdb";
connection.Open();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = con;
adapter = new OleDbDataAdapter("Select * From 信息", connection);
adapter.SelectCommand = command;
dsnew = new DataSet();
adapter.Fill(dsnew, "user");
thetable = dsnew.Tables["user"];
信息DataGridView.DataSource = thetable;
}
} private void button3_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
f1.Show();
this.Hide();
} private void button4_Click(object sender, EventArgs e)
{
if (MessageBox.Show("你确定删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
信息DataGridView.Rows.RemoveAt(信息DataGridView.SelectedRows[0].Index);
else
{
Form1 f1 = new Form1();
f1.Show();
this.Hide();
}
} private void 信息DataGridView_CurrentCellChanged(object sender, EventArgs e)
{
//信息DataGridView内容显示到textbox里,可是加入这个事件之后,进行查询、删除的操作就无法调试通过了,提示(this.textBox2.Text = this.信息DataGridView.CurrentRow.Cells[0].Value.ToString(); “未将对 象引用设置到对象的实例”。) this.textBox2.Text = this.信息DataGridView.CurrentRow.Cells[0].Value.ToString();
this.textBox3.Text = this.信息DataGridView.CurrentRow.Cells[1].Value.ToString();
this.textBox4.Text = this.信息DataGridView.CurrentRow.Cells[2].Value.ToString();
this.textBox5.Text = this.信息DataGridView.CurrentRow.Cells[3].Value.ToString();
this.textBox6.Text = this.信息DataGridView.CurrentRow.Cells[4].Value.ToString();
this.textBox7.Text = this.信息DataGridView.CurrentRow.Cells[5].Value.ToString();
} }
}
解决方案 »
- 【讨论】Xenocode 2010 Danny Su版是否有毒?
- notifyIcon 控件的ShowBalloonTip方法里能添加链接吗
- 【在线】如何迭代继承了DictionaryBase类的集合类?
- 谁能给我举例说明回调函数的使用呢?
- word中插入图片的问题!
- 进来看看,马上散分!!up 多给
- 我发送到消息队列中的消息,过了几天就自动删除了,请问这是什么原因?
- 关于Form程序中的DataGrid的当前行变化时问题
- 怎样把DataRow数组中的,所有行赋给一个DataTable对象?在线急等!
- 超出编译器限制:行不能超过2046个字符?该如何处理?在线等待解决。。。。。
- 如何将XML文件转换成XSD最好有详细的步骤!!!
- 数字字符串 转成 sql中float 类型数据用啥函数?
加一个判断,如果DataGridView的行数大于0再进行操作。