首页 > 代码库 > VB.net 笔记 (一)
VB.net 笔记 (一)
目的:创建与数据库交互的asp.net例子
一、新建一个空解决方案(也可直接建项目)
二、在项目中新建一个项目,然后新建三层 分别是:DAL 、BLL 、Model
三、创建数据库(我使用vs2010自带数据库 感觉比较方便)
首先第一次使用在 服务器资源管理器中 要建立一个数据库 在空白处 右键 即可建立
然后插入数据
注意:红框 连接数据库的时候 会需要字符串 点击红框 你懂得!!
四、DBHelper编写(网上资料) DBHelper 写在DAL中
1 Imports System 2 Imports System.Collections 3 Imports System.Collections.Specialized 4 Imports System.Data 5 Imports System.Data.SqlClient 6 Imports System.Configuration 7 Imports System.Data.Common 8 Imports System.Collections.Generic 9 10 ‘Namespace Tianli.DBUtility 11 12 ‘修改成實際項目的命名空間名稱 13 ‘‘‘ <summary> 14 ‘‘‘ 資料訪問基礎類(基於Oracle) 15 ‘‘‘ 可以用戶可以修改滿足自己專案的需要。 16 ‘‘‘ </summary> 17 Public MustInherit Class DBHelper 18 19 ‘ Protected Shared connectionString As String = ConfigurationSettings.AppSettings("conectiongstring") 20 Protected Shared connectionString As String = "Data Source=WISEPERSON-2006\SQLEXPRESS;Initial Catalog=tom;Integrated Security=True;Pooling=False" 21 22 Public Sub New() 23 End Sub 24 25 #Region "公用方法" 26 27 Public Shared Function Exists(ByVal strSql As String, ByVal ParamArray cmdParms As SqlParameter()) As Boolean 28 Dim obj As Object = Getsingle(strSql, cmdParms) 29 Dim cmdresult As Integer 30 If ([Object].Equals(obj, Nothing)) OrElse ([Object].Equals(obj, System.DBNull.Value)) Then 31 cmdresult = 0 32 Else 33 cmdresult = Integer.Parse(obj.ToString()) 34 End If 35 If cmdresult = 0 Then 36 Return False 37 Else 38 Return True 39 End If 40 End Function 41 Public Shared Function Exists(ByVal strSql As String) As Boolean 42 Dim obj As Object = Getsingle(strSql) 43 Dim cmdresult As Integer 44 If ([Object].Equals(obj, Nothing)) OrElse ([Object].Equals(obj, System.DBNull.Value)) Then 45 cmdresult = 0 46 Else 47 cmdresult = Integer.Parse(obj.ToString()) 48 End If 49 If cmdresult = 0 Then 50 Return False 51 Else 52 Return True 53 End If 54 End Function 55 #End Region 56 57 #Region "執行簡單SQL語句" 58 ‘‘‘ <summary> 59 ‘‘‘ 执行sql语句,返回影响的记录数 60 ‘‘‘ </summary> 61 ‘‘‘ <param name="Sqlstring">sql语句</param> 62 ‘‘‘ <returns>影响记录数据</returns> 63 ‘‘‘ <remarks></remarks> 64 Public Shared Function ExecuteSql(ByVal Sqlstring As String) As Integer 65 Dim connection As New SqlConnection(connectionString) 66 If connection.State = ConnectionState.Closed Then 67 connection.Open() 68 End If 69 Dim trans As SqlTransaction = connection.BeginTransaction 70 Dim cmd As New SqlCommand 71 cmd.Connection = connection 72 cmd.Transaction = trans 73 cmd.CommandText = Sqlstring 74 Try 75 Dim row As Integer = cmd.ExecuteNonQuery 76 trans.Commit() 77 Return row 78 Catch ex As Exception 79 trans.Rollback() 80 Throw New Exception(ex.Message) 81 End Try 82 83 End Function 84 85 86 Public Shared Sub ExecuteSqltran(ByVal sqlstringList As ArrayList) 87 Dim conn As New SqlConnection(connectionString) 88 conn.Open() 89 If conn.State = ConnectionState.Closed Then 90 conn.Open() 91 End If 92 Dim trans As SqlTransaction = conn.BeginTransaction 93 Dim cmd As New SqlCommand 94 cmd.Connection = conn 95 cmd.Transaction = trans 96 Try 97 For n As Integer = 0 To sqlstringList.Count - 1 98 Dim strsql As String = sqlstringList(n).ToString() 99 If strsql.Trim().Length > 1 Then100 cmd.CommandText = strsql101 cmd.ExecuteNonQuery()102 End If103 Next104 trans.Commit()105 Catch ex As Exception106 trans.Rollback()107 Throw New Exception(ex.Message)108 End Try109 End Sub110 111 ‘‘‘ <summary> 112 ‘‘‘ 執行一條計算查詢結果語句,返回查詢結果(object)。 113 ‘‘‘ </summary> 114 ‘‘‘ <param name="SQLString">計算查詢結果語句</param> 115 ‘‘‘ <returns>查詢結果(object)</returns> 116 Public Shared Function Getsingle(ByVal sqlstring) As Object117 Dim connection As New SqlConnection(connectionString)118 If connection.State = ConnectionState.Closed Then119 connection.Open()120 End If121 Dim cmd As New SqlCommand(sqlstring, connection)122 Try123 Dim obj As Object = cmd.ExecuteScalar()124 If ([Object].Equals(obj, Nothing)) Or ([Object].Equals(obj, System.DBNull.Value)) Then125 Return Nothing126 Else127 Return obj128 End If129 Catch ex As Exception130 connection.Close()131 Throw New Exception(ex.Message)132 End Try133 134 End Function135 136 ‘‘‘ <summary> 137 ‘‘‘ 執行查詢語句,返回SqlExecuteReader 138 ‘‘‘ </summary> 139 ‘‘‘ <param name="strSQL">查詢語句</param> 一般用於聚集函數返回值140 ‘‘‘ <returns>SqlExecuteReader</returns> 141 Public Shared Function SqlExecuteReader(ByVal strSQL As String) As SqlDataReader142 Dim connection As New SqlConnection(connectionString)143 If connection.State = ConnectionState.Closed Then144 connection.Open()145 End If146 Dim cmd As New SqlCommand(strSQL, connection)147 Try148 Dim myReader As SqlDataReader = cmd.ExecuteReader()149 Return myReader150 Catch ex As Exception151 Throw New Exception(ex.Message)152 End Try153 End Function154 155 ‘‘‘ <summary> 156 ‘‘‘ 執行帶一個存儲過程參數的的SQL語句。 157 ‘‘‘ </summary> 158 ‘‘‘ <param name="SQLString">SQL語句</param> 159 ‘‘‘ <param name="content">參數內容,比如一個欄位是格式複雜的文章,有特殊符號,可以通過這個方式添加</param> 160 ‘‘‘ <returns>影響的記錄數</returns> 161 162 Public Shared Function ExecuteSql(ByVal SQLString As String, ByVal content As String) As Integer163 Dim connection As New SqlConnection(connectionString)164 Dim cmd As New SqlCommand(SQLString, connection)165 Dim myParameter As New System.Data.SqlClient.SqlParameter("@content", SqlDbType.NText)166 myParameter.Value =http://www.mamicode.com/ content167 cmd.Parameters.Add(myParameter)168 Try169 connection.Open()170 Dim rows As Integer = cmd.ExecuteNonQuery()171 Return rows172 Catch E As System.Data.SqlClient.SqlException173 Throw New Exception(E.Message)174 Finally175 cmd.Dispose()176 connection.Close()177 End Try178 End Function179 180 ‘‘‘ <summary>181 ‘‘‘ 返回最大值182 ‘‘‘ </summary>183 ‘‘‘ <param name="FieldName">字段名称</param>184 ‘‘‘ <param name="TableName">表名称</param>185 ‘‘‘ <returns></returns>186 ‘‘‘ <remarks></remarks>187 Public Shared Function GetMaxID(ByVal FieldName As String, ByVal TableName As String) As Integer188 Dim strsql As String = "select max(" + FieldName + ")+1 from " + TableName189 Dim obj As Object = Getsingle(strsql)190 If obj Is Nothing Then191 Return 1192 Else193 Return Integer.Parse(obj.ToString())194 End If195 End Function196 197 ‘ <summary> 198 ‘ 向資料庫裏插入圖像格式的欄位(和上面情況類似的另一種實例) 199 ‘ </summary> 200 ‘ <param name="strSQL">SQL語句</param> 201 ‘ <param name="fs">圖像位元組,資料庫的欄位類型為image的情況</param> 202 ‘ <returns>影響的記錄數</returns> 203 204 ‘//保存SQL server2000的Image205 ‘string pathName; 206 ‘pathName = this.openFileDialog1.FileName; 207 ‘//將圖像讀入到字節數組 208 ‘System.IO.FileStream fs = new System.IO.FileStream(pathName,System.IO.FileMode.Open,System.IO.FileAccess.Read); 209 ‘byte[] buffByte = new byte[fs.Length]; 210 ‘fs.Read(buffByte,0,(int)fs.Length); 211 ‘fs.Close(); 212 ‘fs = null; 213 214 ‘public byte[] ConvertImage(Image image) 215 ‘{ 216 ‘ FileStream fs=new FileStream("imagetemp",FileMode.Create,FileAccess.Write,FileShare.None); 217 ‘ BinaryFormatter bf = new BinaryFormatter(); 218 ‘ bf.Serialize(fs,(object)image); 219 ‘ fs.Close(); 220 ‘ fs=new FileStream("imagetemp",FileMode.Open,FileAccess.Read,FileShare.None); 221 ‘ byte[] bytes = new byte[fs.Length]; 222 ‘ fs.Read(bytes,0,(int)fs.Length); 223 ‘ fs.Close(); 224 ‘ return bytes; 225 ‘} 226 227 ‘public Image ReadImage(byte[] bytes) 228 ‘{ 229 ‘ FileStream fs=new FileStream("imagetemp1",FileMode.Create,FileAccess.Write,FileShare.None); 230 ‘ foreach(byte a in bytes) 231 ‘ { 232 ‘ fs.WriteByte(a); 233 ‘ } 234 ‘ fs.Close(); 235 ‘ fs=new FileStream("imagetemp1",FileMode.Open,FileAccess.Read,FileShare.None); 236 ‘ BinaryFormatter bf = new BinaryFormatter(); 237 ‘ object obj=bf.Deserialize(fs); 238 ‘ fs.Close(); 239 ‘ return (Image)obj; 240 ‘} 241 Public Shared Function ExecuteSqlInsertImg(ByVal strSQL As String, ByVal fs As Byte()) As Integer242 Dim connection As New SqlConnection(connectionString)243 If connection.State = ConnectionState.Closed Then244 connection.Open()245 End If246 Dim cmd As New SqlCommand(strSQL, connection)247 Dim myParameter As New SqlParameter("@fs", SqlDbType.Image)248 myParameter.Value =http://www.mamicode.com/ fs249 cmd.Parameters.Add(myParameter)250 Try251 Dim rows As Integer = cmd.ExecuteNonQuery252 Return rows253 Catch ex As Exception254 Throw New Exception(ex.Message)255 Finally256 cmd.Dispose()257 connection.Close()258 End Try259 End Function260 261 262 ‘‘‘ <summary> 263 ‘‘‘ 執行查詢語句,返回DataSet 264 ‘‘‘ </summary> 265 ‘‘‘ <param name="SQLString">查詢語句</param> 266 ‘‘‘ <returns>DataSet</returns>267 268 Public Shared Function Query(ByVal SQLString As String) As DataSet269 Dim connection As New SqlConnection(connectionString)270 Dim ds As New DataSet271 Try272 connection.Open()273 Dim myda As New SqlDataAdapter(SQLString, connection)274 myda.Fill(ds)275 Catch ex As Exception276 Throw New Exception(ex.Message)277 End Try278 Return ds279 End Function280 281 #End Region282 283 #Region "消息模塊"284 ‘Public Shared Function Show(ByVal page As System.Web.UI.Page, ByVal msg As String)285 ‘ page.RegisterStartupScript("message", "<script language=‘javascript‘ defer>alert(‘" + msg.ToString() + "‘);</script>")286 ‘End Function287 #End Region288 289 #Region "執行帶參數的SQL語句"290 291 Private Shared Sub PrepareCommand(ByRef cmd As SqlCommand, ByRef conn As SqlConnection, ByRef trans As SqlTransaction, ByRef cmdText As String, ByRef cmdParms As SqlParameter())292 If conn.State = ConnectionState.Closed Then293 conn.Open()294 End If295 cmd.Connection = conn296 cmd.CommandText = cmdText297 If Not trans Is Nothing Then298 cmd.Transaction = trans299 End If300 301 cmd.CommandType = CommandType.Text302 If Not cmdParms Is Nothing Then303 For Each parm As SqlParameter In cmdParms304 cmd.Parameters.Add(parm)305 Next306 End If307 End Sub308 309 Public Shared Function ExecuteSql(ByVal SQLString As String, ByVal ParamArray cmdParms As SqlParameter()) As Integer310 Dim connection As New SqlConnection(connectionString)311 If connection.State = ConnectionState.Closed Then312 connection.Open()313 End If314 Dim trans As SqlTransaction = connection.BeginTransaction315 Dim cmd As New SqlCommand316 Try317 PrepareCommand(cmd, connection, trans, SQLString, cmdParms)318 Dim rows As Integer = cmd.ExecuteNonQuery()319 cmd.Parameters.Clear()320 trans.Commit()321 Return rows322 Catch ex As Exception323 trans.Rollback()324 Throw New Exception(ex.Message)325 Finally326 connection.Close()327 cmd.Dispose()328 End Try329 End Function330 331 332 ‘*333 ‘ Dim parameters As OracleParameter() = {New OracleParameter("DPPM_", OracleType.Number), New OracleParameter("Issue_id_", OracleType.Number), New OracleParameter("code1_id_", OracleType.Number), New OracleParameter("defectcode_id_", OracleType.Number)}334 ‘ parameters(0).Value = http://www.mamicode.com/dppm335 ‘ parameters(1).Value = http://www.mamicode.com/issue_id336 ‘ parameters(2).Value = http://www.mamicode.com/code1_id337 ‘ parameters(3).Value = http://www.mamicode.com/defect_code_id338 ‘ Return ITSC.DbHelperSQL.ExecuteSP("Updatecsm_issue_code", parameters)339 ‘*‘340 Private Shared Sub PrepareCommandSP(ByVal cmd As SqlCommand, ByVal conn As SqlConnection, ByVal trans As SqlTransaction, ByVal cmdText As String, ByVal cmdParms As SqlParameter())341 If conn.State <> ConnectionState.Open Then342 conn.Open()343 End If344 cmd.Connection = conn345 If Not trans Is Nothing Then346 cmd.Transaction = trans347 End If348 cmd.CommandText = cmdText349 cmd.CommandType = CommandType.StoredProcedure350 If Not cmdParms Is Nothing Then351 For Each parm As SqlParameter In cmdParms352 cmd.Parameters.Add(parm)353 Next354 End If355 End Sub356 357 358 Public Shared Function ExecuteSP(ByVal SP As String, ByVal ParamArray cmdParms As SqlParameter()) As Integer359 Dim connection As New SqlConnection(connectionString)360 If connection.State = ConnectionState.Closed Then361 connection.Open()362 End If363 Dim trans As SqlTransaction = connection.BeginTransaction()364 Dim cmd As New SqlCommand365 Try366 PrepareCommandSP(cmd, connection, trans, SP, cmdParms)367 Dim rows As Integer = cmd.ExecuteNonQuery()368 cmd.Parameters.Clear()369 trans.Commit()370 Return rows371 Catch ex As System.Data.SqlClient.SqlException372 trans.Rollback()373 Throw New Exception(ex.Message)374 End Try375 End Function376 377 378 ‘‘‘ <summary> 379 ‘‘‘ 執行一條計算查詢結果語句,返回查詢結果(object)。 380 ‘‘‘ </summary> 381 ‘‘‘ <param name="SQLString">計算查詢結果語句</param> 382 ‘‘‘ <returns>查詢結果(object)</returns> 383 Public Shared Function GetSingle(ByVal SQLString As String, ByVal ParamArray cmdParms As SqlParameter()) As Object384 Dim connection As New SqlConnection(connectionString)385 Dim cmd As New SqlCommand386 Try387 PrepareCommand(cmd, connection, Nothing, SQLString, cmdParms)388 Dim obj As Object = cmd.ExecuteScalar()389 cmd.Parameters.Clear()390 If ([Object].Equals(obj, Nothing)) OrElse ([Object].Equals(obj, System.DBNull.Value)) Then391 Return Nothing392 Else393 Return obj394 End If395 Catch e As System.Data.SqlClient.SqlException396 Throw New Exception(e.Message)397 End Try398 End Function399 400 ‘‘‘ <summary>401 ‘‘‘ 执行查询语句,返回DataReader402 ‘‘‘ </summary>403 ‘‘‘ <param name="SQLString">查询语句</param>404 ‘‘‘ <param name="cmdParms">查询参数</param>405 ‘‘‘ <returns>DataReader</returns>406 ‘‘‘ <remarks>DataReader</remarks>407 Public Shared Function ExecuteReader(ByVal SQLString As String, ByVal ParamArray cmdParms As SqlParameter()) As SqlDataReader408 Dim connection As New SqlConnection(connectionString)409 Dim cmd As New SqlCommand410 Try411 PrepareCommand(cmd, connection, Nothing, SQLString, cmdParms)412 Dim myReader As SqlDataReader = cmd.ExecuteReader()413 cmd.Parameters.Clear()414 Return myReader415 Catch e As System.Data.SqlClient.SqlException416 Throw New Exception(e.Message)417 End Try418 End Function419 420 421 ‘‘‘ <summary> 422 ‘‘‘ 執行查詢語句,返回DataSet 423 ‘‘‘ </summary> 424 ‘‘‘ <param name="SQLString">查詢語句</param> 425 ‘‘‘ <returns>DataSet</returns> 426 Public Shared Function Query(ByVal SQLString As String, ByVal ParamArray cmdParms As SqlParameter()) As DataSet427 Dim connection As New SqlConnection(connectionString)428 Dim cmd As New SqlCommand429 PrepareCommand(cmd, connection, Nothing, SQLString, cmdParms)430 Dim Myda As New SqlDataAdapter(cmd)431 Dim ds As New DataSet432 Try433 Myda.Fill(ds, "ds")434 cmd.Parameters.Clear()435 Catch ex As System.Data.SqlClient.SqlException436 Throw New Exception(ex.Message)437 End Try438 Return ds439 End Function440 441 ‘‘‘ <summary> 442 ‘‘‘ 執行多條SQL語句,實現資料庫事務。 443 ‘‘‘ </summary> 444 ‘‘‘ <param name="SQLStringList">SQL語句的哈希表(key為sql語句,value是該語句的OracleParameter[])</param> 445 Public Shared Sub ExecuteSqlTran(ByVal SQLStringList As Hashtable)446 Dim conn As New SqlConnection(connectionString)447 conn.Open()448 Dim trans As SqlTransaction = conn.BeginTransaction()449 Dim cmd As New SqlCommand450 Try451 ‘迴圈 452 For Each myDE As DictionaryEntry In SQLStringList453 Dim cmdText As String = myDE.Key.ToString()454 Dim cmdParms As SqlParameter() = DirectCast(myDE.Value, SqlParameter())455 PrepareCommand(cmd, conn, trans, cmdText, cmdParms)456 Dim val As Integer = cmd.ExecuteNonQuery()457 cmd.Parameters.Clear()458 trans.Commit()459 Next460 Catch461 trans.Rollback()462 Throw463 End Try464 End Sub465 #End Region466 467 #Region "存儲過程操作"468 469 ‘‘‘ <summary> 470 ‘‘‘ 執行存儲過程 471 ‘‘‘ </summary> 472 ‘‘‘ <param name="storedProcName">存儲過程名</param> 473 ‘‘‘ <param name="parameters">存儲過程參數</param> 474 ‘‘‘ <returns>OracleDataReader</returns> 475 Public Shared Function RunProcedure(ByVal storedProcName As String, ByVal parameters As IDataParameter()) As SqlDataReader476 Dim connection As New SqlConnection(connectionString)477 Dim returnReader As SqlDataReader478 connection.Open()479 Dim command As SqlCommand = BuildQueryCommand(connection, storedProcName, parameters)480 command.CommandType = CommandType.StoredProcedure481 returnReader = command.ExecuteReader()482 Return returnReader483 End Function484 485 ‘‘‘ <summary> 486 ‘‘‘ 執行存儲過程 487 ‘‘‘ </summary> 488 ‘‘‘ <param name="storedProcName">存儲過程名</param> 489 ‘‘‘ <param name="parameters">存儲過程參數</param> 490 ‘‘‘ <param name="tableName">DataSet結果中的表名</param> 491 ‘‘‘ <returns>DataSet</returns> 492 Public Shared Function RunProcedure(ByVal storedProcName As String, ByVal parameters As IDataParameter(), ByVal tableName As String) As DataSet493 Dim connection As New SqlConnection(connectionString)494 Dim dataSet As New DataSet495 connection.Open()496 Dim sqlDA As New SqlDataAdapter497 sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, parameters)498 sqlDA.Fill(dataSet, tableName)499 connection.Close()500 Return dataSet501 End Function502 ‘‘‘ <summary> 503 ‘‘‘ 構建 OracleCommand 物件(用來返回一個結果集,而不是一個整數值) 504 ‘‘‘ </summary> 505 ‘‘‘ <param name="connection">資料庫連接</param> 506 ‘‘‘ <param name="storedProcName">存儲過程名</param> 507 ‘‘‘ <param name="parameters">存儲過程參數</param> 508 ‘‘‘ <returns>OracleCommand</returns> 509 Private Shared Function BuildQueryCommand(ByVal connection As SqlConnection, ByVal storedProcName As String, ByVal parameters As IDataParameter()) As SqlCommand510 Dim command As New SqlCommand(storedProcName, connection)511 command.CommandType = CommandType.StoredProcedure512 For Each parameter As SqlParameter In parameters513 command.Parameters.Add(parameter)514 Next515 Return command516 End Function517 518 ‘‘‘ <summary> 519 ‘‘‘ 執行存儲過程,返回影響的行數 520 ‘‘‘ </summary> 521 ‘‘‘ <param name="storedProcName">存儲過程名</param> 522 ‘‘‘ <param name="parameters">存儲過程參數</param> 523 ‘‘‘ <param name="rowsAffected">影響的行數</param> 524 ‘‘‘ <returns></returns> 525 Public Shared Function RunProcedure(ByVal storedProcName As String, ByVal parameters As IDataParameter(), ByRef rowsAffected As Integer) As Integer526 Dim connection As New SqlConnection(connectionString)527 Dim result As Integer528 connection.Open()529 Dim command As SqlCommand = BuildIntCommand(connection, storedProcName, parameters)530 rowsAffected = command.ExecuteNonQuery()531 result = CInt(command.Parameters("ReturnValue").Value)532 ‘Connection.Close(); 533 Return result534 End Function535 536 ‘‘‘ <summary> 537 ‘‘‘ 創建 OracleCommand 物件實例(用來返回一個整數值) 538 ‘‘‘ </summary> 539 ‘‘‘ <param name="storedProcName">存儲過程名</param> 540 ‘‘‘ <param name="parameters">存儲過程參數</param> 541 ‘‘‘ <returns>OracleCommand 物件實例</returns> 542 Private Shared Function BuildIntCommand(ByVal connection As SqlConnection, ByVal storedProcName As String, ByVal parameters As IDataParameter()) As SqlCommand543 Dim command As SqlCommand = BuildQueryCommand(connection, storedProcName, parameters)544 command.Parameters.Add(New SqlParameter("ReturnValue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, False, 0, _545 0, String.Empty, DataRowVersion.[Default], Nothing))546 Return command547 End Function548 #End Region549 End Class550 ‘End Namespace
五、在BLL中写业务类 stu
1 Public Class stu 2 Function test() As DataSet 3 4 ‘ Dim dt As System.Data.DataTable 5 Dim ds As DataSet 6 ds = DAL.DBHelper.Query("select * from reg") ‘利用dbhelper中的查询方法 查询出结果 给dataSet 7 test = ds ‘ 返回结果 类似return 8 End Function 9 10 End Class
六、创建asp主页 index.aspx (在web.config中设置主页) 拖一个gridview控件用于显示数据
F7进入index.aspx.vb 编辑
1 Public Class index 2 Inherits System.Web.UI.Page 3 4 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 5 Dim st As New BLL.stu ‘注意new 实例化bll中的stu类 6 Dim para As DataSet 7 8 para = st.test() ‘返回dataset结果 类型是dataset 9 GridView1.DataSource = para ‘把结果给gridview10 GridView1.DataBind() ‘绑定给gridview11 12 13 End Sub14 15 End Class
1 <?xml version="1.0" encoding="utf-8"?> 2 3 4 <configuration> <!--<configuration>节根元素,其它节都是在它的内部.--> 5 6 <connectionStrings> 7 <add name="ApplicationServices" 8 connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" 9 providerName="System.Data.SqlClient" />10 </connectionStrings>11 12 <system.web>13 <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />14 15 <authentication mode="Forms">16 <forms loginUrl="~/Account/Login.aspx" timeout="2880" />17 </authentication>18 19 <membership>20 <providers>21 <clear/>22 <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"23 enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"24 maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"25 applicationName="/" />26 </providers>27 </membership>28 29 <profile>30 <providers>31 <clear/>32 <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>33 </providers>34 </profile>35 36 <roleManager enabled="false">37 <providers>38 <clear/>39 <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />40 <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />41 </providers>42 </roleManager>43 44 </system.web>45 46 47 <!--设置web服务-->48 <system.webServer>49 <defaultDocument>50 <files>51 <clear />52 <add value=http://www.mamicode.com/"index.aspx" />53 <!--<add value=http://www.mamicode.com/"Default.htm" />54 <add value=http://www.mamicode.com/"Default.asp" />55 <add value=http://www.mamicode.com/"index.htm" />56 <add value=http://www.mamicode.com/"index.html" />-->57 </files>58 </defaultDocument>59 <modules runAllManagedModulesForAllRequests="true"/>60 </system.webServer>61 </configuration>
现在运行
VB.net 笔记 (一)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。