不知道怎么说,直接给代码吧!
private void binganshouy_Load(object sender, EventArgs e)//程序启动时填充数据!
{
SqlConnection conn = new SqlConnection(conStr);
string sqlStr = "select * from [BingRen]";
SqlDataAdapter ada = new SqlDataAdapter(sqlStr, conn);
ada.Fill(this.dianZiBingLiDataSet8, "BingRen"); } private void textBox4_TextChanged(object sender, EventArgs e)//程序启动时textBox4.text会改变并根据它对数据进行操作
{
string username = textBox4.Text.Trim();
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
string cmdStr = "select * from [basy] where 病案编号='" + username + "'";
SqlCommand sqlCom = new SqlCommand(cmdStr, conn);
SqlDataReader sRead = sqlCom.ExecuteReader();
if (sRead.Read() == false)//在数据库中插入一行
{
DataRow row = this.dianZiBingLiDataSet8.basy.NewRow();
row["病案编号"] = textBox4.Text;
this.dianZiBingLiDataSet8.basy.Rows.Add(row);
this.basyTableAdapter.Update(this.dianZiBingLiDataSet8.basy);
this.dianZiBingLiDataSet8.basy.AcceptChanges();
SqlDataAdapter ada = new SqlDataAdapter(conStr, conn);
ada.Fill(this.dianZiBingLiDataSet8, "basy"); }
else if (sRead.Read() == true)//填充数据
{
SqlDataAdapter ada = new SqlDataAdapter(conStr, conn);
ada.Fill(this.dianZiBingLiDataSet8, "basy");
}
}窗口中有N个控件都和对应的数据库表进行了绑定。
现在问题是需要的功能都能实现,可当程序打开窗体时会有10-20秒的等待时间。感觉速度太慢了!
开始认为是上面这填充和插入影响了速度,把它们都注销后。运行程序打开窗体还是太慢。不知道是那出的问题。请高手指教!
private void binganshouy_Load(object sender, EventArgs e)//程序启动时填充数据!
{
SqlConnection conn = new SqlConnection(conStr);
string sqlStr = "select * from [BingRen]";
SqlDataAdapter ada = new SqlDataAdapter(sqlStr, conn);
ada.Fill(this.dianZiBingLiDataSet8, "BingRen"); } private void textBox4_TextChanged(object sender, EventArgs e)//程序启动时textBox4.text会改变并根据它对数据进行操作
{
string username = textBox4.Text.Trim();
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
string cmdStr = "select * from [basy] where 病案编号='" + username + "'";
SqlCommand sqlCom = new SqlCommand(cmdStr, conn);
SqlDataReader sRead = sqlCom.ExecuteReader();
if (sRead.Read() == false)//在数据库中插入一行
{
DataRow row = this.dianZiBingLiDataSet8.basy.NewRow();
row["病案编号"] = textBox4.Text;
this.dianZiBingLiDataSet8.basy.Rows.Add(row);
this.basyTableAdapter.Update(this.dianZiBingLiDataSet8.basy);
this.dianZiBingLiDataSet8.basy.AcceptChanges();
SqlDataAdapter ada = new SqlDataAdapter(conStr, conn);
ada.Fill(this.dianZiBingLiDataSet8, "basy"); }
else if (sRead.Read() == true)//填充数据
{
SqlDataAdapter ada = new SqlDataAdapter(conStr, conn);
ada.Fill(this.dianZiBingLiDataSet8, "basy");
}
}窗口中有N个控件都和对应的数据库表进行了绑定。
现在问题是需要的功能都能实现,可当程序打开窗体时会有10-20秒的等待时间。感觉速度太慢了!
开始认为是上面这填充和插入影响了速度,把它们都注销后。运行程序打开窗体还是太慢。不知道是那出的问题。请高手指教!
多的话 会很慢的