<script type="text/javascript">
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
高手来帮我看一下我的代码了??
Imports System.Data
Imports System
Imports System.Data.SqlClient
Public Class Class1
Public myconn As SqlConnection
Public mycomm As SqlCommand
Public mydt As DataTable
Public Function DBopen() As Boolean
Try
myconn = New SqlConnection( Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs )
myconn.Open()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Function
Public Function DBclose() As Boolean
Try
myconn.Close()
myconn = Nothing
myconn.Dispose()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Function
End Class
这是我在一个类中定义数据库连接,,我觉得不太好,,但是我又不会改。。
请那位大哥大姐帮我给好一点咯。。
这样定义到页面上我要用到myconn时候,,我觉得不到他的返回值哦。
总觉得这样写的是在不怎么好的
望指正。。
__________________________________________________________________________
你定义的是函数,函数是需要返回值的,而你没有明确的指定。
你可以把你的函数改成子过程,也就是 sub
另外你也可以指定函数的返回值的。如:
Imports System.Data
Imports System
Imports System.Data.SqlClient
Public Class Class1
Public myconn As SqlConnection
Public mycomm As SqlCommand
Public mydt As DataTable
Public Function DBopen() As Boolean
Try
myconn = New SqlConnection( Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs )
myconn.Open()
dbopen=true
Catch ex As Exception
MessageBox.Show(ex.ToString)
dbopen=false
End Try
End Function
Public Function DBclose() As Boolean
Try
myconn.Close()
myconn = Nothing
myconn.Dispose()
dbclose=true
Catch ex As Exception
MessageBox.Show(ex.ToString)
declose =false
End Try
End Function
End Class
__________________________________________________________________________
你的连接已经写死,硬编码
看看微软的企业库中数据库操作部分
__________________________________________________________________________
请问楼上的兄弟“微软的企业库中数据库操作部分” 在那里看哦。。给个地址哦。。
谢谢拉
__________________________________________________________________________
需要学习。看微软的企业库中数据库操作部分
__________________________________________________________________________
高手来帮我看一下我的代码了??
Imports System.Data
Imports System
Imports System.Data.SqlClient
Public Class Class1
Public myconn As SqlConnection
Public mycomm As SqlCommand
Public mydt As DataTable
Public Function DBopen() As Boolean
Try
myconn = New SqlConnection( Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs )
myconn.Open()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Function
Public Function DBclose() As Boolean
Try
myconn.Close()
myconn = Nothing
myconn.Dispose()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Function
End Class
这是我在一个类中定义数据库连接,,我觉得不太好,,但是我又不会改。。
请那位大哥大姐帮我给好一点咯。。
这样定义到页面上我要用到myconn时候,,我觉得不到他的返回值哦。
总觉得这样写的是在不怎么好的
望指正。。
__________________________________________________________________________
你定义的是函数,函数是需要返回值的,而你没有明确的指定。
你可以把你的函数改成子过程,也就是 sub
另外你也可以指定函数的返回值的。如:
Imports System.Data
Imports System
Imports System.Data.SqlClient
Public Class Class1
Public myconn As SqlConnection
Public mycomm As SqlCommand
Public mydt As DataTable
Public Function DBopen() As Boolean
Try
myconn = New SqlConnection( Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs )
myconn.Open()
dbopen=true
Catch ex As Exception
MessageBox.Show(ex.ToString)
dbopen=false
End Try
End Function
Public Function DBclose() As Boolean
Try
myconn.Close()
myconn = Nothing
myconn.Dispose()
dbclose=true
Catch ex As Exception
MessageBox.Show(ex.ToString)
declose =false
End Try
End Function
End Class
__________________________________________________________________________
你的连接已经写死,硬编码
看看微软的企业库中数据库操作部分
__________________________________________________________________________
请问楼上的兄弟“微软的企业库中数据库操作部分” 在那里看哦。。给个地址哦。。
谢谢拉
__________________________________________________________________________
需要学习。看微软的企业库中数据库操作部分
__________________________________________________________________________