Procedure is as follows:
Option Explicit Off
Imports System. The Data. SqlClient
# Region "database basic operation class library"
Public Class PublicClass
# Region "database connection class"
Public sqlconn As New SqlClient. SqlConnection
Public Sub open_conn ()
'Dim sqlconnstr As String
Try
Sqlconn. The ConnectionString=(" server=127.0.0.1; Integrated security=False; Initial Catalog=YNCSys; User ID=sa; The Pwd=adminsa226200 ")
Catch the ex As Exception
Throw the ex
End the Try
End Sub
# End Region
# Region "select statement, need to enter T - SQL statement"
The Public Function dataSelect (ByVal STRSQL As String, ByVal strTableName As String) As the DataSet
Dim mydataset As New DataSet
Dim mySqlAdapter As SqlClient. SqlDataAdapter
Try
Sqlconn. The Open ()
MySqlAdapter=New SqlClient. SqlDataAdapter (STRSQL, sqlconn)
MySqlAdapter. The Fill (mydataset strTableName)
Sqlconn. Close ()
MySqlAdapter=Nothing
Catch the ex As Exception
If sqlconn. State=ConnectionState. Open Then
Sqlconn. Close ()
End the If
Throw the ex
End the Try
Return mydataset
End the Function
# End Region
# Region "data into operation, the parameters of the insert statement and table name"
Public Sub dataInsert (ByVal strSql As String, ByVal strTableName As String)
Dim mysqlcomm As SqlClient. SqlCommand
Try
Sqlconn. The Open ()
Mysqlcomm=New SqlClient. SqlCommand (strSql, sqlconn)
Mysqlcomm. ExecuteNonQuery ()
Sqlconn. Close ()
Mysqlcomm=Nothing
Catch the ex As Exception
If sqlconn. State=ConnectionState. Open Then
Sqlconn. Close ()
End the If
Throw the ex
End the Try
End Sub
# End Region
# Region "modify data module, parameters for updata and table name"
Public Sub dataUpdate (ByVal strSql As String, ByVal strTableName As String)
Dim mysqlcomm As New SqlClient. SqlCommand
Try
Sqlconn. The Open ()
Mysqlcomm=New SqlClient. SqlCommand (strSql, sqlconn)
Mysqlcomm. ExecuteNonQuery ()
Sqlconn. Close ()
Mysqlcomm=Nothing
Catch the ex As Exception
If sqlconn. State=ConnectionState. Open Then
Sqlconn. Close ()
End the If
Throw the ex
End the Try
End Sub
# End Region
# Region "delete data operation, the parameters for the delete and want to delete the table name"
Public Sub dataDelete (ByVal strSql As String, ByVal strTableName As String)
Dim mysqlcomm As New SqlClient. SqlCommand
Try
Sqlconn. The Open ()
Mysqlcomm=New SqlClient. SqlCommand (strSql, sqlconn)
Mysqlcomm. ExecuteNonQuery ()
Sqlconn. Close ()
Mysqlcomm=Nothing
Catch the ex As Exception
If sqlconn. State=ConnectionState. Open Then
Sqlconn. Close ()
End the If
Throw the ex
End the Try
End Sub
# End Region
# Region "controls the binding method, parameters for the SQL stored procedures and DataGridView control"
Public Sub BDDataToDataGridView (ByVal PRO As String, ByVal DGV As DataGridView)
Sqlconn. The Open ()
Dim SQLCMD As the New System. The Data. SqlClient. SqlCommand
SQLCMD. Connection=sqlconn
Dim da As the New System. The Data. SqlClient. SqlDataAdapter ()
Da. SelectCommand=SQLCMD
Da.SelectCommand.Com mandType=CommandType. StoredProcedure
Da.SelectCommand.Com mandText="select * from '" + PRO. ToString (). The Trim () +"' "' by SQL stored procedures binding data
Dim ds As New DataSet ()
Da. SelectCommand. Connection=sqlconn
Da. The Fill (ds)
DGV. The DataSource=ds. Tables (0)
DGV. Refresh ()
End Sub
# Region "controls the binding method, parameters for the SQL stored procedure and the ComboBox control"
Public Sub BDToComboBox (ByVal PRO As String, ByVal As ComboBox ComboBox)
Sqlconn. The Open ()
Dim SQLCMD As the New System. The Data. SqlClient. SqlCommand
SQLCMD. Connection=sqlconn
Dim da As the New System. The Data. SqlClient. SqlDataAdapter ()
Da. SelectCommand=SQLCMD
Da.SelectCommand.Com mandText="select * from '" + ComboBox. SelectedText. Trim +"' "' by SQL stored procedures binding data
Dim ds As New DataSet ()
Da. SelectCommand. Connection=sqlconn
Da. The Fill (ds)
ComboBox. The DataSource=ds. Tables (0)
ComboBox. Refresh ()
End Sub
# End Region
# End Region
The End of the Class
# End Region
CodePudding user response:
Error so clear: the connectionstring is not set!Then look at your code, inside the open_conn method has carried on the set, then the next question is this method is called? The easiest way to do that in this line to add a breakpoint, see in front of the error will not run to the breakpoint will understand,