




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
ASP.NET於SQL Server之Web網頁資料庫存取關鍵程式碼(以SqlClient連線方法)目錄1.顯示全部資料表內容複製程式碼22.查詢某紀錄複製程式碼33.以關鍵字的方式查詢某紀錄複製程式碼54.刪除某紀錄複製程式碼75.新增某紀錄複製程式碼96.修改某紀錄複製程式碼111. /顯示全部資料表內容複製程式碼Imports System.DataImports System.Data.SqlClient SqlClient 連結資料庫 # # SQL Server 2005 # # 以 Windows 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=(local);database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; # # 以 SQL Server 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Persist Security Info=False;User ID=帳戶名稱;Password=密碼;Initial Catalog=資料庫名稱;Server=localhost Dim conn As SqlConnection = New SqlConnection(str) conn.Open() 查詢資料 Dim str1 As String = select * from 資料表 Dim adp1 As SqlDataAdapter = New SqlDataAdapter(str1, conn) 將查詢結果放到記憶體set1上的1a 表格內 Dim set1 As DataSet = New DataSet adp1.Fill(set1, 1a) 將記憶體的資料集合存放到視窗畫面上的DataGrid上 GridView1.DataSource = set1.Tables(1a) GridView1.DataBind() 關閉資料庫的連結 conn.Close()2. /查詢某紀錄複製程式碼Imports System.DataImports System.Data.SqlClient SqlClient 連結資料庫 # # SQL Server 2005 # # 以 Windows 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=(local);database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; # # 以 SQL Server 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Persist Security Info=False;User ID=帳戶名稱;Password=密碼;Initial Catalog=資料庫名稱;Server=localhost Dim conn As SqlConnection = New SqlConnection(str) conn.Open() 查詢資料 Dim str1 As String = Select * from 資料表 where name = jack Dim adp1 As SqlDataAdapter = New SqlDataAdapter(str1, conn) 將查詢結果放到記憶體set1上的1a 表格內 Dim set1 As DataSet = New DataSet adp1.Fill(set1, 1a) 將記憶體的資料集合存放到視窗畫面上的DataGridView上 GridView1.DataSource = set1.Tables(1a) GridView1.DataBind() 關閉資料庫的連結 conn.Close()注意查詢(a). SQL查詢某紀錄語法n Select * from 1a where name = jack(b). 當有變數時的SQL查詢語法(C)n “Select * from 1a where name = ” + textBox1.text + “”(c). 當有變數時的SQL查詢語法(VB.NET)n “Select * from 1a where name = ” & textBox1.text & “”3. /以關鍵字的方式查詢某紀錄複製程式碼Imports System.DataImports System.Data.SqlClient SqlClient 連結資料庫 # # SQL Server 2005 # # 以 Windows 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=(local);database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; # # 以 SQL Server 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Persist Security Info=False;User ID=帳戶名稱;Password=密碼;Initial Catalog=資料庫名稱;Server=localhost Dim conn As SqlConnection = New SqlConnection(str) conn.Open() 查詢資料 Dim str1 As String = Select * from 資料表 where name like %jack% Dim adp1 As SqlDataAdapter = New SqlDataAdapter(str1, conn) 將查詢結果放到記憶體set1上的1a 表格內 Dim set1 As DataSet = New DataSet adp1.Fill(set1, 1a) 將記憶體的資料集合存放到視窗畫面上的DataGrid上 GridView1.DataSource = set1.Tables(1a) GridView1.DataBind() 關閉資料庫的連結 conn.Close()注意查詢(a). SQL查詢某紀錄語法n Select * from 1a where name like %jack%(b). 當有變數時的SQL查詢語法(C)n “Select * from 1a where name like %” + textBox1.text + “%”(c). 當有變數時的SQL查詢語法(VB.NET)n “Select * from 1a where name like %” & textBox1.text & “%”4. /刪除某紀錄複製程式碼 SqlClient 連結資料庫 # # SQL Server 2005 # # 以 Windows 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=(local);database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; # # 以 SQL Server 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Persist Security Info=False;User ID=帳戶名稱;Password=密碼;Initial Catalog=資料庫名稱;Server=localhost Dim conn As SqlConnection = New SqlConnection(str) conn.Open()刪除資料庫內的記錄設定刪除記錄的 SQL語法 及資料庫執行指令OleDbCommand Dim str1 As String = delete * from 資料表 where name = jack Dim cmd As SqlCommand = New SqlCommand(str1, conn) 執行資料庫指令SqlCommand cmd.ExecuteNonQuery() 關閉資料庫的連結 conn.Close() 顯示成功刪除記錄的訊息() MessageBox.Show(成績刪除一筆記錄了, 成功刪除, MessageBoxButtons.OKCancel,MessageBoxIcon.Information)刪除(a). SQL刪除某紀錄語法n delete * from 1a where name = jack(b). 當有變數時的SQL刪除詢語法(C)n “delete * from 1a where name = ” + textBox1.text + “”(c). 當有變數時的SQL刪除語法(VB.NET)n “delete * from 1a where name = ” & textBox1.text & “”5. /新增某紀錄複製程式碼Imports System.DataImports System.Data.SqlClient SqlClient 連結資料庫 # # SQL Server 2005 # # 以 Windows 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=(local);database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; # # 以 SQL Server 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Persist Security Info=False;User ID=帳戶名稱;Password=密碼;Initial Catalog=資料庫名稱;Server=localhost Dim conn As SqlConnection = New SqlConnection(str) conn.Open() 新增記錄到資料庫內設定新增記錄的 SQL語法 及資料庫執行指令SqlCommand Dim str1 As String = Insert Into 資料表(name,chi)Values(jack,90) Dim cmd As SqlCommand = New SqlCommand(str1, conn) 執行資料庫指令SqlCommand cmd.ExecuteNonQuery() 關閉資料庫的連結 conn.Close() 顯示成功新增記錄的訊息() MessageBox.Show(成績新增一筆記錄了, 成功新增, MessageBoxButtons.OKCancel,MessageBoxIcon.Information)新增(a). SQL新增某紀錄語法n Insert Into 1a(name,chi)Values(jack,90)(b). 當有變數時的SQL新增語法(C)n “Insert Into 1a(name,chi)Values ” + textBoxName.text + “,” + Int32.Parse(textBoxName.text) + “)”;(c). 當有變數時的SQL新增語法(VB.NET)n “Insert Into 1a(name,chi)Values ” & textBoxName.text & “,” & Int32.Parse(textBoxName.text) & “)”;”6. /修改某紀錄複製程式碼Imports System.DataImports System.Data.SqlClient SqlClient 連結資料庫 # # SQL Server 2005 # # 以 Windows 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=(local);database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;Integrated Security=SSPI; # # 以 SQL Server 驗證登入帳戶 (3種方法)# Dim str As String = Server=localhost;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Server=伺服器名稱;database=資料庫名稱;User Id=帳戶名稱;Password=密碼; Dim str As String = Persist Security Info=False;User ID=帳戶名稱;Password=密碼;Initial Catalog=資料庫名稱;Server=localhost Dim conn As SqlConnection = New SqlConnection(str) conn.Open() 修改資料庫內的記錄
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 买地定金合同范本
- 2025至2030年中国成套投梭连杆行业投资前景及策略咨询研究报告
- 2025至2030年中国忠义千秋行业发展研究报告
- 2025至2030年中国强碱阴离子交换树脂市场分析及竞争策略研究报告
- 2025至2030年中国建筑挂钩行业投资前景及策略咨询报告001
- 2025至2030年中国带托架密闭型包装箱数据监测研究报告
- 2025至2030年中国工程箱市场现状分析及前景预测报告
- 2025至2030年中国工业用电风扇网罩行业投资前景及策略咨询报告
- 防非安全教育课件
- 高一试卷真题语文及答案
- 新教材高中生物选择性必修2课件:1 2 种群数量的变化(人教版)
- 车辆租赁服务保障计划
- 《装配式混凝土建筑》全套教学课件
- (二模)温州市2025届高三第二次适应性考试语文试卷(含答案)
- 2024-2025学年人教版数学八年级下册第一次月考模拟练习(含答案)
- 2025届河北省承德市、张家口市高三下学期一模考试英语试题(含答案)
- 2024山西云时代技术有限公司社会招聘59人笔试参考题库附带答案详解
- Unit+4+Eat+Well+Section+A+2a~2e课件-2024-2025学年人教版(2024)英语七年级下册+
- 2025年部编版新教材语文一年级下册期中测试题(有答案)
- 《FAB销售法则》课件
- 卫生院、社区卫生服务中心《死亡医学证明书》上报制度
评论
0/150
提交评论