学校栏做成下拉菜单形式,可以从里面选择,如果没有想要的,可以自己输入学校名称,以后就会存在下拉菜单中。(和access数据库连接)
以下是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace HospitalResearch
{
public partial class frmHospitalInfoEdit : Form
{
public frmHospitalInfoEdit()
{
InitializeComponent();
} private void btnReturn_Click(object sender, EventArgs e)
{
this.Close();
} private void btnAdd_Click(object sender, EventArgs e)
{ string sSchool = comboBox1.Text.Trim(); //学校名称
string sSQL = string.Format(
"INSERT INTO 学校表 (学校名称) VALUES " +
"('{0}')",
sSchool
);
int iRet = DbHelperACE.ExecuteSql(sSQL); if (iRet == 1)
{
MessageBox.Show("添加成功,点击确定返回");
this.Close();
}
else
{
MessageBox.Show("添加失败,请检查数据的数据或数据库设置");
}
} private void btnEdit_Click(object sender, EventArgs e)
{ string sSchool = comboBox1.Text.Trim(); //学校名称
string sSQL = string.Format(
"UPDATE 学校表 SET " +
"学校名称='{0}' WHERE 序号=" + Global.lSelectItemEditID,
sSchool
);
int iRet = DbHelperACE.ExecuteSql(sSQL); if (iRet == 1)
{
MessageBox.Show("修改成功,点击确定返回");
this.Close();
}
else
{
MessageBox.Show("修改失败,请检查数据的数据或数据库设置");
}
} private void frmHospitalInfoEdit_Load(object sender, EventArgs e)
{
btnAdd.Enabled = Global.bSelcctAddNew;
btnAdd.Visible = Global.bSelcctAddNew;
btnEdit.Enabled = !Global.bSelcctAddNew;
btnEdit.Visible = !Global.bSelcctAddNew; if (!Global.bSelcctAddNew)
{
this.LoadData();
}
} private void LoadData()
{
string sSQL = "SELECT * FROM 学校表 WHERE 序号 = " + Global.lSelectItemEditID; DataSet ds = DbHelperACE.Query(sSQL);
comboBox1.Text = ds.Tables[0].Rows[0][1].ToString();
}
}
}
以下是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace HospitalResearch
{
public partial class frmHospitalInfoEdit : Form
{
public frmHospitalInfoEdit()
{
InitializeComponent();
} private void btnReturn_Click(object sender, EventArgs e)
{
this.Close();
} private void btnAdd_Click(object sender, EventArgs e)
{ string sSchool = comboBox1.Text.Trim(); //学校名称
string sSQL = string.Format(
"INSERT INTO 学校表 (学校名称) VALUES " +
"('{0}')",
sSchool
);
int iRet = DbHelperACE.ExecuteSql(sSQL); if (iRet == 1)
{
MessageBox.Show("添加成功,点击确定返回");
this.Close();
}
else
{
MessageBox.Show("添加失败,请检查数据的数据或数据库设置");
}
} private void btnEdit_Click(object sender, EventArgs e)
{ string sSchool = comboBox1.Text.Trim(); //学校名称
string sSQL = string.Format(
"UPDATE 学校表 SET " +
"学校名称='{0}' WHERE 序号=" + Global.lSelectItemEditID,
sSchool
);
int iRet = DbHelperACE.ExecuteSql(sSQL); if (iRet == 1)
{
MessageBox.Show("修改成功,点击确定返回");
this.Close();
}
else
{
MessageBox.Show("修改失败,请检查数据的数据或数据库设置");
}
} private void frmHospitalInfoEdit_Load(object sender, EventArgs e)
{
btnAdd.Enabled = Global.bSelcctAddNew;
btnAdd.Visible = Global.bSelcctAddNew;
btnEdit.Enabled = !Global.bSelcctAddNew;
btnEdit.Visible = !Global.bSelcctAddNew; if (!Global.bSelcctAddNew)
{
this.LoadData();
}
} private void LoadData()
{
string sSQL = "SELECT * FROM 学校表 WHERE 序号 = " + Global.lSelectItemEditID; DataSet ds = DbHelperACE.Query(sSQL);
comboBox1.Text = ds.Tables[0].Rows[0][1].ToString();
}
}
}
string sSQL = string.Format(
"INSERT INTO 学校表 (学校名称) VALUES " +
"('{0}')",
sSchool
);
你的查询语法有问题,根本就不能再SQL Server执行,可以执行了再放到C#里面!