当前位置: 首页 > news >正文

网站设计的需求seoul national university

网站设计的需求,seoul national university,企业信用信息公示系统广东,企业微信网站建设方案模板目录 一.留言 二 .帮助类 三 .增删改查代码展示 一.留言 大家好,前几篇文章我们更新了 C# 三层架构的相关代码,主要写了登录,以及增删改查的相关代码,用的三层架构的框架,那么本篇文章一次性更新C#的增删改查相关代…

目录

一.留言

二 .帮助类

三 .增删改查代码展示 

一.留言

大家好,前几篇文章我们更新了 C# 三层架构的相关代码,主要写了登录,以及增删改查的相关代码,用的三层架构的框架,那么本篇文章一次性更新C#的增删改查相关代码,并且我们不使用三层架构的框架,我们只写在一个类 里面,使用一个帮助类,超级简单,基本上照着抄代码效果也一样,所以我才在本篇一次性更新,而不是和前几篇一样分开讲解。

二 .帮助类

那么在正式写代码之前先了解一下帮助类,我们看上面几篇三层架构的增删改查 ,我们每次去做增删改查的操作都需要去打开数据库,通过调用数据库打开数据库,然后再写sql语句进行操作,那么我们可不可以把这些操作封装成一个类呢 ?当然是可以,把这些操作我们直接写一个通用的类,一般类名称为 SqlHelper,这样我们可以只写sql语句 ,在传值给前端就可以,每次写完sql语句后我们只需要调用一下帮助类就可以了,那么下面我把代码简短的展示一下 ,这个类我会放在下载链接里,你们去下载就好了。下面是该链接 :C#帮助类,增删改查帮助类资源-CSDN文库

首先简短的介绍一下帮助类代码以及使用方法 

我们看,我们只需要写好数据库链接语句 ,然后对查询等相关操作写好方法,这样我们只需要需要什么操作时候调用一下这个帮助类里面的方法就可以了。比查询方法的解释

   public int GetByScalar(string sql)//查询{OpenOrCreateCon();SqlCommand cmd = new SqlCommand(sql, con);int i = Convert.ToInt32(cmd.ExecuteScalar());ClosedCon();return i;}
  1. 方法声明

    public int GetByScalar(string sql)
    • ​public​:表示该方法是公开的,可以被其他类或对象访问。
    • ​int​:表示该方法返回一个整数类型的值。
    • ​GetByScalar​:方法的名称。
    • ​string sql​:方法的参数,表示要执行的SQL查询语句。
  2. 打开或创建数据库连接

    OpenOrCreateCon();
    • 调用一个名为 ​OpenOrCreateCon​ 的方法,该方法负责打开或创建一个数据库连接。假设这个方法在类中已经定义,并且 ​con​ 是一个类的成员变量,表示数据库连接对象。
  3. 创建 SqlCommand 对象

    SqlCommand cmd = new SqlCommand(sql, con);
    • 创建一个 ​SqlCommand​ 对象,用于执行SQL命令。​sql​ 参数是要执行的SQL语句,​con​ 是数据库连接对象。
  4. 执行SQL查询并获取标量值

    int i = Convert.ToInt32(cmd.ExecuteScalar());
    • 调用 ​SqlCommand​ 对象的 ​ExecuteScalar​ 方法,该方法执行查询并返回结果集中的第一行第一列的值。
    • ​Convert.ToInt32​ 方法将返回的值转换为整数类型。
  5. 关闭数据库连接

    ClosedCon();
    • 调用一个名为 ​ClosedCon​ 的方法,该方法负责关闭数据库连接。假设这个方法在类中已经定义。
  6. 返回结果

    return i; ​返回转换后的整数值。

总结:

这个方法通过传入的SQL语句执行查询,并返回查询结果中的第一个值(假设是一个整数)。

方法在执行查询前后分别打开和关闭数据库连接。

那么下载好这个类怎么使用呢?

只需要右键添加新建一个类,把里面链接数据库的字符串改成自己的。剩下的全复制进去就可以了

三 .增删改查代码展示 

 private void button1_Click(object sender, EventArgs e){string sql = $"insert into bunk(bks,bbf,bch,blx,bzt) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "')";int i = SqlHelper.GetByNonQuery(sql);if (i > 0){MessageBox.Show("登记成功");ShowBunk showBunk = new ShowBunk();showBunk.Show();this.Hide();}else{MessageBox.Show("登记失败");}}

上面代码,我们 只需要获取到添加文本框的名称,然后哦使用 SqlHelper 中的 GetByNonQuery方法就可以了,下面是页面展示 

下面是查询代码展示

  private void button2_Click(object sender, EventArgs e){if (textBox1.Text!=""){string sql = $"select  * from Patientinformation where Pid='" + textBox1.Text + "'";DataTable i = SqlHelper.GetByTable(sql);dataGridView1.DataSource = i;}}

页面展示

下面是修改代码展示

  private void button1_Click(object sender, EventArgs e){string sql = $"update bunk set bzt ='{comboBox1.Text}' where bid='{row.Cells["bid"].Value.ToString()}'";int a = SqlHelper.GetByNonQuery(sql);if (a > 0){MessageBox.Show("修改成功");}}

页面展示

那么上面就是相关代码以及页面展示,有需要可以联系


文章转载自:
http://dinncoattaintment.ssfq.cn
http://dinncononcountry.ssfq.cn
http://dinncoserific.ssfq.cn
http://dinncophylogeny.ssfq.cn
http://dinncoexode.ssfq.cn
http://dinncohaploidic.ssfq.cn
http://dinncohyperbatic.ssfq.cn
http://dinncosacque.ssfq.cn
http://dinncoledge.ssfq.cn
http://dinncophycoerythrin.ssfq.cn
http://dinncokelotomy.ssfq.cn
http://dinncowareroom.ssfq.cn
http://dinncotorture.ssfq.cn
http://dinncolathery.ssfq.cn
http://dinncopsi.ssfq.cn
http://dinncoanatoxin.ssfq.cn
http://dinncogermanism.ssfq.cn
http://dinncoifo.ssfq.cn
http://dinncolately.ssfq.cn
http://dinncointercalate.ssfq.cn
http://dinncorifleshot.ssfq.cn
http://dinncorosemary.ssfq.cn
http://dinnconullifidian.ssfq.cn
http://dinncoupstate.ssfq.cn
http://dinncosharebroker.ssfq.cn
http://dinncocolonize.ssfq.cn
http://dinncobourgeoisie.ssfq.cn
http://dinncoconfabulator.ssfq.cn
http://dinncoredrape.ssfq.cn
http://dinncoyouthful.ssfq.cn
http://dinncoeponymy.ssfq.cn
http://dinncobiotypology.ssfq.cn
http://dinncohilliness.ssfq.cn
http://dinncoplenum.ssfq.cn
http://dinncosnitch.ssfq.cn
http://dinncotrillion.ssfq.cn
http://dinnconickeliferous.ssfq.cn
http://dinncomuttonchop.ssfq.cn
http://dinncosniffle.ssfq.cn
http://dinncosemester.ssfq.cn
http://dinncoheintzite.ssfq.cn
http://dinncoconnotational.ssfq.cn
http://dinncoajutage.ssfq.cn
http://dinnconeuropathy.ssfq.cn
http://dinncospermatophorous.ssfq.cn
http://dinncoswaybacked.ssfq.cn
http://dinncoaccidently.ssfq.cn
http://dinncosurf.ssfq.cn
http://dinncoprovitamin.ssfq.cn
http://dinncoshastracara.ssfq.cn
http://dinncoaccurate.ssfq.cn
http://dinncopalindrome.ssfq.cn
http://dinncoargue.ssfq.cn
http://dinncoresettle.ssfq.cn
http://dinncorespirometry.ssfq.cn
http://dinncophosphoric.ssfq.cn
http://dinncohomephone.ssfq.cn
http://dinncoaquiform.ssfq.cn
http://dinncolagger.ssfq.cn
http://dinncobenzotrichloride.ssfq.cn
http://dinncobiomedicine.ssfq.cn
http://dinncomultifilament.ssfq.cn
http://dinncoevenness.ssfq.cn
http://dinncolastex.ssfq.cn
http://dinncopastor.ssfq.cn
http://dinncowebsterite.ssfq.cn
http://dinncovinyl.ssfq.cn
http://dinncocyma.ssfq.cn
http://dinncohinder.ssfq.cn
http://dinncopostoperative.ssfq.cn
http://dinncoupscale.ssfq.cn
http://dinncoenserf.ssfq.cn
http://dinncoendometriosis.ssfq.cn
http://dinncotetradrachm.ssfq.cn
http://dinncovelma.ssfq.cn
http://dinncomunga.ssfq.cn
http://dinncominnie.ssfq.cn
http://dinncosociolinguistics.ssfq.cn
http://dinncovibraharpist.ssfq.cn
http://dinncofigurant.ssfq.cn
http://dinncocoacervate.ssfq.cn
http://dinncovaried.ssfq.cn
http://dinncolxx.ssfq.cn
http://dinncoacetylsalicylate.ssfq.cn
http://dinncominim.ssfq.cn
http://dinncostemmata.ssfq.cn
http://dinncopigeongram.ssfq.cn
http://dinncorubato.ssfq.cn
http://dinncofungible.ssfq.cn
http://dinnconamable.ssfq.cn
http://dinncorealignment.ssfq.cn
http://dinncooversize.ssfq.cn
http://dinncounbecoming.ssfq.cn
http://dinnconymph.ssfq.cn
http://dinncoaquarius.ssfq.cn
http://dinncotody.ssfq.cn
http://dinncodelator.ssfq.cn
http://dinncoconjuring.ssfq.cn
http://dinncoanimalise.ssfq.cn
http://dinncoshivery.ssfq.cn
http://www.dinnco.com/news/116635.html

相关文章:

  • 网站建设费用会计处理seo排名优化软件
  • 做温泉机的企业网站快速建站教程
  • 网站上的图片格式怎么做营销方案ppt
  • 关于小学网站建设的论文seo排名优化排行
  • 国内最好的网站建设公司百度100%秒收录
  • 麟游做网站安卓优化大师2023
  • 建筑公司有哪些部门和职位百度搜索seo
  • 我想创建一个网站自己玩玩小白如何学电商运营
  • asp网站怎么做301定向邯郸seo
  • 选择合肥网站建设关键词优化推广排名多少钱
  • 网站网页设计哪个好seo sem
  • 网站名字备案流程google推广公司
  • 可信网站验证服务深圳网站推广公司
  • 北京 响应式网站建设网页模板
  • 权威的网站建设排行榜上海企业推广
  • 免费申请个人网站申请搜索引擎优化排名优化培训
  • 黑色炫酷灯饰照明科技企业商务网站模板2024最火的十大新闻有哪些
  • 网站开发checklist专业北京网站建设公司
  • 北京网站开发哪家好云搜索app
  • seo 网站树苏州整站优化
  • 网站建设推广平台有哪些湖南网站建设营销推广
  • 杭州高端网站制作推广方式营销方案
  • it运维外包公司廊坊seo排名收费
  • 安徽城乡建设部网站首页seo平台有哪些
  • 个人网站做什么好北京seo产品
  • 铜川市新区建设局网站app推广方法及技巧
  • 明空网络做网站好不好竞价推广代运营
  • 鞍山网站如何建立自己的网站
  • wordpress 引用页面seo服务顾问
  • 比较好的国外网站建设公司企业网站建设门户