加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB.net数据库编程(07):SQLserver中的通讯录

发布时间:2020-12-17 07:57:44 所属栏目:百科 来源:网络整理
导读:前面用过Access的通讯录,下面用一个SQLserver的通讯录。 首先,在SQL2012中建立一个表,插入一个记录: [sql] view plain copy print ? useSales go create table txl (tID int identity(10000,1) primary key , tName varchar (50) not null , tEmail varc
前面用过Access的通讯录,下面用一个SQLserver的通讯录。


首先,在SQL2012中建立一个表,插入一个记录:

[sql] view plain copy print ?
  1. useSales
  2. go
  3. createtabletxl
  4. (tIDintidentity(10000,1)primarykey,
  5. tNamevarchar(50)notnull,
  6. tEmailvarchar(50),226); color:inherit; line-height:18px"> tMobilechar(11),85); line-height:18px"> tHomePhonevarchar(12),226); color:inherit; line-height:18px"> tMemovarchar(2000)--备注
  7. )
  8. insertintotxlvalues('令狐冲','yms@sohu.com','13681246528','62349087','一个剑客')

注:identity(seed,incre)第一个表示起点,第二表示增量。10000,1表示记录从10000开始,每一个记录数据增加加1.

所以第二条记录的标号就是10001.


下面用VB.net对其插入记录,并显示。

注意:SQL语句中的单引号


[vb] ?
    ImportsSystem.Data.SqlClient
  1. PublicClassForm1
  2. DimcnAsSqlConnection
  3. DimcmdAsSqlCommand
  4. DimdaAsSqlDataAdapter
  5. DimdsAsDataSet
  6. PrivateSubButton1_Click(senderAsObject,eAsEventArgs)HandlesButton1.Click
  7. Try
  8. cn=NewSqlConnection("DataSource=.;InitialCatalog=Sales;IntegratedSecurity=False;UserID=sa;Password=123456;")
  9. cn.Open()
  10. cmd=NewSqlCommand("insertintotxlvalues('"&TextBox1.Text&"','"&TextBox2.Text&"','"&TextBox3.Text&"','"&TextBox4.Text&"','"&TextBox5.Text&"')",cn)
  11. cmd.ExecuteNonQuery()
  12. cn.Close()
  13. MessageBox.Show("插入成功")
  14. CatchexAsException
  15. MessageBox.Show(ex.ToString&cmd.CommandText)
  16. EndTry
  17. EndSub
  18. PrivateSubButton3_Click(senderAsObject,eAsEventArgs)HandlesButton3.Click
  19. da=NewSqlDataAdapter("select*fromtxl",cn)
  20. ds=NewDataSet()
  21. da.Fill(ds,"txl")
  22. DataGridView1.DataSource=ds.Tables("txl")
  23. cn.Close()
  24. EndSub
  25. PrivateSubButton2_Click(senderAsObject,eAsEventArgs)
  26. EndClass




由引我们学习了Access和SQlserver查看记录和修改记录的例子。

一,查询与非查询的操作。

二,存储过程的操作,参数是如何添加的。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读