winform c# access
1.insert
public void NewData(String GroupNameSet)
{
String sql = "insert into mytable(GroupNameSet) values(@GroupNameSet)"
OleDbConnection cn = new OleDbConnection(_ConnectionString)
OleDbCommand cmd = new OleDbCommand(sql, cn)
cmd.Parameters.AddWithValue("@GroupNameSet", GroupNameSet)
if (cn.State != ConnectionState.Open)
cn.Open()
try
{
cmd.ExecuteNonQuery()
}
catch (Exception err)
{
throw err
}
finally
{
if (cn.State != ConnectionState.Closed)
cn.Close()
}
}
2.update
public void UpdateData(String GroupNameSet,String pkid)
{
String sql = "update mytable set GroupNameSet=@GroupNameSet where pkid=@pkid"
OleDbConnection cn = new OleDbConnection(_ConnectionString)
OleDbCommand cmd = new OleDbCommand(sql, cn)
cmd.Parameters.AddWithValue("@GroupNameSet", GroupNameSet)
cmd.Parameters.AddWithValue("@pkid", pkid)
if (cn.State != ConnectionState.Open)
cn.Open()
try
{
cmd.ExecuteNonQuery()
}
catch (Exception err)
{
throw err
}
finally
{
if (cn.State != ConnectionState.Closed)
cn.Close()
}
}
3.delete
public void DeleteData(String pkid)
{
String sql = "delete from mytable where pkid=@pkid"
OleDbConnection cn = new OleDbConnection(_ConnectionString)
OleDbCommand cmd = new OleDbCommand(sql, cn)
cmd.Parameters.AddWithValue("@pkid", pkid)
if (cn.State != ConnectionState.Open)
cn.Open()
try
{
cmd.ExecuteNonQuery()
}
catch (Exception err)
{
throw err
}
finally
{
if (cn.State != ConnectionState.Closed)
cn.Close()
}
}
4.select
public DataTable GetData()
{
//从数据库中读出数据
String sql = "select * from mytable"
OleDbDataAdapter da = new OleDbDataAdapter(sql, new OleDbConnection(_ConnectionString))
//da.SelectCommand.Parameters.Add(p0)
try
{
if (cn.State != ConnectionState.Open)
cn.Open()
DataTable dt = new DataTable()
da.Fill(dt)
return dt
}
catch (Exception err)
{
return null
}
finally
{
if (cn.State != ConnectionState.Closed)
cn.Close()
}
}
5.connection string:
public static String ConnectionString
{
get
{
String str = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0Data Source={0}\myAccessDatabase.mdb", System.Windows.Forms.Application.StartupPath)
return str
}
}
6.在Form的新增按钮事件中:
this.NewData(this.TextBox1.Text.Trim())
Form的LoadData
DataTable dt= GetData()
this.datagridView1.DataSource=dt
删除和更新,假设用到Grid,则
foreach(DataGridViewRow row in this.DataGridView.Rows)
{
if(row.Selected)
{
.....
}
}
宾馆由于工作性质的关系,主要是为客人提供住宿、餐饮、娱乐、休闲等业务,客人的宾馆入住的舒适情况都直接影响到宾馆的业绩。宾馆管理是现代化商业管理中一个极其重要的工作,该系统可以应用在局域网上,系统地、全面地支持宾馆管理和服务的全过程。主要目标是实现对宾馆内部各种管理的电子化、自动化、提高各个部门之间的办公效率,为高质量的宾馆服务提供保证。该着眼于宾馆的当前管理与未来发展,由宾馆管理人员参与整个研发过程,更加贴近现代宾馆的管理模式与管理风格。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)