[不是问题]我正在尝试创建一个使用MySQL的VB.NET Web应用程序,我目前正在使用经典的asp并需要一些指导 [英] [Not a question] I am trying to create a VB.NET web application that uses MySQL, I am currently using classic asp and need some guidance

查看:66
本文介绍了[不是问题]我正在尝试创建一个使用MySQL的VB.NET Web应用程序,我目前正在使用经典的asp并需要一些指导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个使用MySQL的VB.NET Web应用程序,我目前正在使用经典的asp并需要一些指导。



刚才我包括db_inc每个asp页面的.asp文件,我可以简单地使用以下子程序来提取数据而无需为每个页面重新创建ado /连接字符串。



基本上我正在寻找使用mySQL在VB.NET中实现非常类似的方法帮助



 调用 GetFromDataBase(  SELECT * FROM Users WHERE User_Id = 1,oRsTemp1)

调用 GetFromDatabasePerPage( SELECT * FROM Users WHERE User_Id = 1,oRsTemp1)#incisheds paging

调用 UpdateDataBase( 更新我们ers SET name ='test'WHER User_Id = 1



例子



< pre lang =vb> mySQL = SELECT name FROM users;

调用 GetFromDataBase(mySQL,oRsTemp1)

如果 oRsTemp1.EOF 然后
执行 while oRsTemp1.EOF
response.Write oRsTemp1( 名称





< pre lang =HTML> <%
' ************
'
执行数据库的功能
' ************ *

'
------------------------------------ -----------
' 商店连接字符串
'
-----------------------------------------------

Dim oConnectionString

blnShowDebugStatsQueries = True
blnShowDebugStats = True
blnShowDebugStatsQueries = True

oConnectionString = DSN = test; DATABASE = testdb; Persist Security Info = True; Pooling = False

< span class =code-string>' -------------------------- ---------------------
'
创建数据库连接
' -------------------------------------- ---------

如果不是blnInstall那么
设置oDataConn = Server.CreateObject(ADODB.Connection)
oDataConn.Open oCo nnectionString
设置oCommand = Server.CreateObject(ADODB.Command)
设置oRsTemp1 = Server.CreateObject(ADODB.Recordset)
设置oRsTemp2 = Server.CreateObject(ADODB.Recordset )
设置oRsTemp3 = Server.CreateObject(ADODB.Recordset)
结束如果

strDateDelimiter ='

numCursorType = 3

'------------------ -----------------------------
'SET EXECUTION STATS
'执行计数器。这对调试统计数据非常有用
'--------------------------------------- --------

Dim numTotalExecuteRS,numTotalExecuteScalar,numTotalExecuteNonQuery,numQueryExecutionTime,strQueryBuildup
numTotalExecuteRS = 0:numTotalExecuteScalar = 0:numTotalExecuteNonQuery = 0
numQueryExecutionTime = 0
QueryBuildup =


'------- ----------------------------------------
'调用错误报告的函数
'--------------------------------------------- -

Sub ReportQueryError(Query,strErrorDescription)
如果blnUpgrade = true则
'什么都不做
否则
'关闭我们可能在的任何标签
response.Write
< div id = dbtrappederror > < / textarea的 > < / 选择 >
response.Write
< div style = 宽度:80%; FONT-FAMILY:宋体;字体大小:12像素;字体重量:正常; background-color:#eeeeee;保证金:10月10日10pt 10pt 10pt;填充:20pt 20pt 20pt 20pt; border:1pt solid black >
response.Write
< p style = font-weight:bold >执行错误以下查询和页面执行已终止。< / p >
response.Write
< p style = font-family:courier new ;字体大小:14px的;颜色:#800000 > & Query& < / p >
回复。写
< p> 错误说明: & strErrorDescription& < / p >
response.write
< p> 错误页面: & Request.ServerVariables( URL )& < / p >
response.write
< p> 查询字符串< br /> ;< br /> & Request.QueryString& < / p >
response.Write
< / div > < / div >
Call EndPage()
response.end
结束if
End Sub

'--- --------------------------------------------
'执行查询,并记录记录集
'填写结果
'----------------------------- ------------------

Sub GetFromDataBase(Query,rsTemp)
'开始错误捕获
如果不是(blnDoingTransaction或blnDoingCallback)然后On Error Resume Next

'启动查询执行的计时器
numSt artTime =计时器

'执行查询
oCommand.CommandText =查询
oCommand.CommandType = 1
设置oCommand.ActiveConnection = oDataConn
rsTemp.CursorLocation = 3
rsTemp.Open oCommand ,, 1,numCursorType

'递增计数和查询时间
numQueryExecutionTime = numQueryExecutionTime +(Timer - numStartTime)
numTotalExecuteRS = numTotalExecuteRS + 1
QueryBuildup = QueryBuildup&
< li> & WriteSafe(查询)& < br /> ExecuteRS - 时间: &回合(计时器 - numStartTime,2)* 100& ms < br />< br /> < / li >

'报告错误,结束错误捕获
if err.Description<>
而不是blnDoingTransaction然后调用ReportQueryError(Query,err.Description)
如果不是( blnDoingTransaction或blnDoingCallback)然后出错goto 0

End Sub

'---------------------- -------------------------
'执行非查询 - 即返回
'没有结果(INSERT,更新)
'------------------------------------------- ----

Sub UpdateDataBase(查询)
'启动错误捕获
如果不是(blnDoingTransaction或blnDoingCallback)然后On Error Resume Next

'启动查询执行计时器
numStartTime =计时器

'执行查询
oDataConn.Execute(查询)

'递增计数和查询时间
numQueryExecutionTime = numQueryExecutionTime +(Timer - numStartTime)
numTotalExecuteNonQuery = numTotalExecuteNonQuery + 1
QueryBuildup = QueryBuildup&
< li> & WriteSafe(查询)& < br /> ExecuteNonQuery - 时间: &回合(计时器 - numStartTime,2)* 100& ms < br />< br /> < / li >

'报告错误,结束错误捕获
if err.Description<>
而不是blnDoingTransaction然后调用ReportQueryError(Query,err.Description)
如果不是( blnDoingTransaction或blnDoingCallback)然后出错goto 0
End Sub

'-------------------------- ---------------------
'执行查询,并记录记录集
'填充结果
' - ---------------------------------------------

Sub GetFromDatabasePerPage(Query,rsTemp)
'启动错误捕获
如果不是(blnDoingTransaction或blnDoingCallback)然后On Error Resume Next

'启动查询执行的计时器
numStartTime =定时器

'执行查询
oCommand.CommandText =查询
oCommand.CommandType = 1
设置oCommand.ActiveConnection = oDataConn
rsTemp .CursorLocation = 3
rsTemp.Open oCommand ,, 1,numCursorType

'递增计数和查询时间
numQueryExecutionTime = numQueryExecutionTime +(Time r - numStartTime)
numTotalExecuteRS = numTotalExecuteRS + 1
QueryBuildup = QueryBuildup&
< li> & WriteSafe(查询)& < br /> ExecuteRS - 时间: &回合(计时器 - numStartTime,2)* 100& ms < br />< br /> < / li >

'报告错误,结束错误捕获
if err.Description<>
而不是blnDoingTransaction然后调用ReportQueryError(Query,err.Description)
如果不是( blnDoingTransaction或blnDoingCallback)然后出错goto 0

End Sub

'---------------------- -------------------------
'这个子关闭所有连接。应该在
'调用每个页面的底部,之前和页面重定向
'-------------------------- ---------------------

Sub EndPage()

'关闭所有数据库内容
oDataConn.Close
set oRsTemp1 = nothing
set oRsTemp2 = nothing
set oRsTemp3 = nothing
set oCommand = nothing
set oDataConn = nothing


'在页面底部显示调试统计信息
'如果blnShowDebugStats则
'结束脚本执行计时器
numScriptExecutionTime =计时器 - numScriptExecutionStartTime

response.Write
< div style = text-align:left; width:600px; font-family:verdana; font-size:12px; font-weight:normal; background-color:#eeeeee; margin:10pt 10pt 10pt 10pt; padding:20pt 20pt 20pt 20pt; border:1pt solid black >
response.write
执行的总查询次数: & numTotalExecuteRS + numTotalExecuteScalar + numTotalExecuteNonQuery& < br />
response.write
记录集: & numTotalExecuteRS& < br />
response.write
标量: & numTotalExecuteScalar& < br />
response.write
Nonquerys: & numTotalExecuteNonQuery& < br />
response.Write
< br />
response.Write
总页面执行时间:< span class =code-string>
& round(numScriptExecutionTime,2)* 100& ms < br />
response.Write
查询: & round(numQueryExecutionTime,2)* 100& ms< br />
response.Write
脚本: & round(numScriptExecutionTime - numQueryExecutionTime,2)* 100& ms< br />
response.Write
< br />

'显示已执行
'的所有查询如果blnShowDebugStatsQueries然后
response.Write
执行的查询:< br />
response.Write
< span style = font-size:11px; font-family:courier new ; >< ul> & QueryBuildup& < / ul > < / span >
'结束如果
response.Write
< / div >
'结束如果


结束次级

mySQL =
SELECT name FROM users;

调用GetFromDataBase(mySQL,oRsTemp1)

如果不是oRsTemp1.EOF那么
请勿执行oRsTemp1.EOF
response.Write oRsTemp1(
name
oRsTemp1.MoveNext
循环
结束如果
oRsTemp1.Close

Cal l EndPage()
%>

解决方案

我认为你首先需要的是拥有一个基本的了解ASP.Net。 ASP.Net和ASP经典之间存在很多差异。获取一本书,或为初学者阅读一些教程。以下是您可以查看的许多链接中的一些。



初学者漫步 - 网站开发 [ ^ ]

http://www.asp.net / [ ^ ]


I am trying to create a VB.NET web application that uses MySQL, I am currently using classic asp and need some guidance.

Just now I include db_inc.asp file for each asp page and I can simply use the following subroutines to pull data without needing to recreate ado/connection string for each page.

Basically I am looking for some help to implement a very similar approach in VB.NET using the mySQL

Call GetFromDataBase("SELECT * FROM Users WHERE User_Id = 1", oRsTemp1) 

Call GetFromDatabasePerPage("SELECT * FROM Users WHERE User_Id = 1", oRsTemp1) # incudes paging

Call UpdateDataBase("UPDATE users SET name=’test’ WHERE User_Id = 1")


Example

mySQL = " SELECT name FROM users;"

Call GetFromDataBase(mySQL, oRsTemp1)

If Not oRsTemp1.EOF Then
Do While Not oRsTemp1.EOF
    response.Write oRsTemp1("name")



<%
'***********************************************
'FUNCTIONS TO EXECUTE AGAINST THE DATABASE
'***********************************************

'-----------------------------------------------
' Store Connection String
'-----------------------------------------------

Dim oConnectionString

blnShowDebugStatsQueries = True
blnShowDebugStats = True
blnShowDebugStatsQueries = True

oConnectionString                   = "DSN=test;DATABASE=testdb;Persist Security Info=True;Pooling=False"

'-----------------------------------------------
' CREATE DATABASE CONNECTION
'-----------------------------------------------

If Not blnInstall then
	Set oDataConn       = Server.CreateObject("ADODB.Connection")
	oDataConn.Open oConnectionString
	Set oCommand        = Server.CreateObject("ADODB.Command")
	Set oRsTemp1        = Server.CreateObject("ADODB.Recordset")
	Set oRsTemp2        = Server.CreateObject("ADODB.Recordset")
	Set oRsTemp3        = Server.CreateObject("ADODB.Recordset")
End If

strDateDelimiter = "'"
numCursorType = 3

'-----------------------------------------------
' SET EXECUTION STATS
' Counters for execution. This is useful for debug stats
'-----------------------------------------------

Dim numTotalExecuteRS, numTotalExecuteScalar, numTotalExecuteNonQuery, numQueryExecutionTime, strQueryBuildup
numTotalExecuteRS = 0: numTotalExecuteScalar = 0: numTotalExecuteNonQuery = 0
numQueryExecutionTime = 0
QueryBuildup = ""

'-----------------------------------------------
'Functions called for error reporting
'-----------------------------------------------

Sub ReportQueryError(Query, strErrorDescription)
	If blnUpgrade = true then
		'Do nothing
	Else
		'Close any tags we may be in
		response.Write "<div id=""dbtrappederror""></textarea></select>"
		response.Write "<div style=""width: 80%; font-family:verdana; font-size:12px; font-weight:normal; background-color: #eeeeee; margin: 10pt 10pt 10pt 10pt; padding: 20pt 20pt 20pt 20pt; border: 1pt solid black"">"
		response.Write "<p style=""font-weight: bold"">An error occurred executing the following query, and page execution has been terminated.</p>"
		response.Write "<p style=""font-family:courier new; font-size:14px; color:#800000"">" & Query & "</p>"
		response.write "<p>Error Description :  " & strErrorDescription & "</p>"
		response.write "<p>Page of error :  " & Request.ServerVariables("URL") & "</p>"
		response.write "<p>Query String : <br /><br />" & Request.QueryString & "</p>"
		response.Write "</div></div>"
		Call EndPage()
		response.end
	End if
End Sub

'-----------------------------------------------
' Executes the query, and records the recordset
' filled with the results
'-----------------------------------------------

Sub GetFromDataBase(Query, rsTemp)
	'Start error trapping
	If Not (blnDoingTransaction Or blnDoingCallback) Then On Error Resume Next
	
	'Start the timer for query execution
	numStartTime = Timer
	
	'Execute query
	oCommand.CommandText = Query
	oCommand.CommandType = 1
	Set oCommand.ActiveConnection = oDataConn
	rsTemp.CursorLocation = 3
	rsTemp.Open oCommand, , 1, numCursorType
	
	'Increment count and query time
	numQueryExecutionTime = numQueryExecutionTime + (Timer - numStartTime)
	numTotalExecuteRS = numTotalExecuteRS + 1
	QueryBuildup = QueryBuildup & "<li>" & WriteSafe(Query) & "<br />ExecuteRS - Time: " & Round(Timer - numStartTime, 2) * 100 & "ms<br /><br /></li>"
		
	'Report error, end error trapping
	if err.Description <> "" and not blnDoingTransaction then Call ReportQueryError(Query, err.Description)
	if not (blnDoingTransaction or blnDoingCallback) then on error goto 0

End Sub   

'-----------------------------------------------
'Executes a non-query - i.e. one that returns
'no results (INSERT, UPDATE)
'-----------------------------------------------

Sub UpdateDataBase(Query)
	'Start error trapping
	if not (blnDoingTransaction or blnDoingCallback) then On Error Resume Next
	
	'Start the timer for query execution
	numStartTime = Timer
	
	'Execute query
	oDataConn.Execute(Query)
	
	'Increment count and query time
	numQueryExecutionTime = numQueryExecutionTime + (Timer - numStartTime)
	numTotalExecuteNonQuery = numTotalExecuteNonQuery + 1
	QueryBuildup = QueryBuildup & "<li>" & WriteSafe(Query) & "<br />ExecuteNonQuery - Time: " & Round(Timer - numStartTime, 2) * 100 & "ms<br /><br /></li>"
	
	'Report error, end error trapping
	if err.Description <> "" and not blnDoingTransaction then Call ReportQueryError(Query, err.Description)
	if not (blnDoingTransaction or blnDoingCallback) then on error goto 0	
End Sub

'-----------------------------------------------
' Executes the query, and records the recordset
' filled with the results
'-----------------------------------------------

Sub GetFromDatabasePerPage(Query, rsTemp)
	'Start error trapping
	if not (blnDoingTransaction or blnDoingCallback) then On Error Resume Next
	
	'Start the timer for query execution
	numStartTime = Timer
	
	'Execute query
	oCommand.CommandText = Query
	oCommand.CommandType = 1
	Set oCommand.ActiveConnection = oDataConn
	rsTemp.CursorLocation = 3
	rsTemp.Open oCommand, , 1, numCursorType
	
	'Increment count and query time
	numQueryExecutionTime = numQueryExecutionTime + (Timer - numStartTime)
	numTotalExecuteRS = numTotalExecuteRS + 1
	QueryBuildup = QueryBuildup & "<li>" & WriteSafe(Query) & "<br />ExecuteRS - Time: " & Round(Timer - numStartTime, 2) * 100 & "ms<br /><br /></li>"
		
	'Report error, end error trapping
	if err.Description <> "" and not blnDoingTransaction then Call ReportQueryError(Query, err.Description)
	if not (blnDoingTransaction or blnDoingCallback) then on error goto 0
	
End Sub 

'-----------------------------------------------
' This sub closes all the connections. Should be called at 
' the bottom of everypage, and before and page redirect
'-----------------------------------------------

Sub EndPage()
	
	'Close all database stuff
	oDataConn.Close 
	set oRsTemp1 = nothing
	set oRsTemp2 = nothing
	set oRsTemp3 = nothing
	set oCommand = nothing
	set oDataConn = nothing
	
	
	'Show debug stats at bottom of page
	'If blnShowDebugStats then
		'End script execution timer
		numScriptExecutionTime = Timer - numScriptExecutionStartTime

		response.Write "<div style=""text-align: left; width: 600px; font-family:verdana; font-size:12px; font-weight:normal; background-color: #eeeeee; margin: 10pt 10pt 10pt 10pt; padding: 20pt 20pt 20pt 20pt; border: 1pt solid black"">"
		response.write "Total Querys Executed : " & numTotalExecuteRS + numTotalExecuteScalar + numTotalExecuteNonQuery & "<br />"
		response.write "Recordsets : " & numTotalExecuteRS & "<br />"
		response.write "Scalars : " & numTotalExecuteScalar & "<br />"
		response.write "Nonquerys : " & numTotalExecuteNonQuery & "<br />"
		response.Write "<br />"
		response.Write "Total Page Execution Time : " & round(numScriptExecutionTime, 2) * 100 & "ms<br />"
		response.Write "queries : " & round(numQueryExecutionTime, 2) * 100 & "ms<br />"
		response.Write "scripts : " & round(numScriptExecutionTime - numQueryExecutionTime, 2) * 100 & "ms<br />"
		response.Write "<br />"
		
		'Show all the queries that have executed
		'If blnShowDebugStatsQueries then
			response.Write "Queries Executed:<br />"
			response.Write "<span style=""font-size: 11px; font-family: courier new;""><ul>" & QueryBuildup & "</ul></span>"
		'End If
		response.Write "</div>"
	'end if
	

End Sub

	mySQL = " SELECT name FROM users;"

	Call GetFromDataBase(mySQL, oRsTemp1)

	If Not oRsTemp1.EOF Then
	Do While Not oRsTemp1.EOF
		response.Write oRsTemp1("name")
	oRsTemp1.MoveNext
	Loop
	End If
  	oRsTemp1.Close
  	
Call EndPage()
%>

解决方案

I think what you need first is to have a basic understanding of ASP.Net. There are many differences between ASP.Net and ASP classic. Get a book, or read some tutorials for beginners. Here are just some of the many links that you can check.

Beginner's Walk - Web Development[^]
http://www.asp.net/[^]


这篇关于[不是问题]我正在尝试创建一个使用MySQL的VB.NET Web应用程序,我目前正在使用经典的asp并需要一些指导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆