本文介绍了任何人都可以帮助SQL Connector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





大家好



我想做一个SQL我的应用程序的连接器表格



这是表格的代码:





Hi guys

I want to make a SQL Connector form for my application

this is the code for the form:

Imports System.Data.SqlClient

Public Class frmServer
    Public connectionstring As String

    Private Sub frmServer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        clsMSSQL.Database = txtDatabase.Text
        clsMSSQL.Server = txtServer.Text
        clsMSSQL.con.Open()
        Me.Close()
        frmMain.Show()
    End Sub

    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        Close()
    End Sub

    Private Sub cmdTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest.Click
        Try
            If txtServer.Text = "" OrElse txtDatabase.Text = "" Then
                MessageBox.Show("Fill all the required fields", "SQL Connector", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                clsMSSQL.Database = txtDatabase.Text
                clsMSSQL.Server = txtServer.Text
                clsMSSQL.con.Open()
                clsMSSQL.con.Close()
                MessageBox.Show("Test Connection Successfully!")
            End If
        Catch
            MessageBox.Show("Cannot Established Connection", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub



和这是班级:




and this is the class:

Imports System.Data.SqlClient

Public Class clsMSSQL
    Public Shared Server As String = ""
    Public Shared Database As String = ""
    Public Shared constring As String = "Data Source=" & Server & ";Initial Catalog=" & Database & " ;Integrated Security=True;"
    Public Shared con As New SqlConnection(constring)
    Public Shared Connector As New frmServer()
End Class





这段代码哪里出错了?

我无法连接数据库而导致连接错误。



Where is the wrong in this code?
I can''t connect with database it gives connection error.

推荐答案

Imports System.Data.SqlClient
Public Class clsMSSQL
	Private _Server As String
	Private _Database As String
	Public Property Server() As String
		Get
			Return _Server
		End Get
		Set(ByVal value As String)
			_Server = value
		End Set
	End Property
	Public Property Database() As String
		Get
			Return _Database
		End Get
		Set(ByVal value As String)
			_Database = value
		End Set
	End Property
	Public ReadOnly Property constring() As String
		Get
			Return "Data Source=" & _Server & ";Initial Catalog=" & _Database & " ;Integrated Security=True;"
		End Get
	End Property
End Class





等等...我还没有包括你需要以类似方式改变的其他位



Etc ... I haven''t included the other bits you will need to change in a similar way


这篇关于任何人都可以帮助SQL Connector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 12:11