我一直收到错误:40当试图将数据输入保存到我通过单击按钮创建的SQL数据库时

时间:2016-03-28 12:54:56

标签: vb.net sqlconnection

我是VB的新手,我写了几行代码,但每次运行程序时我都会得到

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

,这是我的代码行

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
    Dim strConnection As String = "Data Source= (local);" & "DataBase='GUU_PATIENT_RECORDDataSet';" & "Integrated Security=yes;"
    Dim strTreatment_price As String = "INSERT INTO Treatment_price(Patient_Name, " & "Patient Address,Hospital_Number,Phone_Number, Admitted Date,Patients Date Of Birth,Blood Group,Genotype,Treatment1,Treatment2,Treatment3,Treatment4,Treatment5,Treatment6,Price_Unit1,Price_Unit2,Price_Unit3,Price_Unit4,Price_Unit5,Price_Unit6, " & "Sub_Total,VAT,Previous_BAl,NET_Total)" & _
    "VALUES ('" & Patient_NameTextBox.Text & "','" & Patient_AddressTextBox.Text & "','" & Hospital_NumberTextBox.Text & "','" & Phone_NumberTextBox.Text & "','" & Blood_Group_TextBox.Text & "','" & GenotypeTextBox.Text & "','" & Treatment1TextBox.Text & "','" & Treatment2TextBox.Text & "','" & Treatment4TextBox.Text & "','" & Treatment5TextBox.Text & "','" & Treatment6TextBox.Text & "','" & Price_Unit1TextBox.Text & "','" & Price_Unit2TextBox.Text & "','" & Price_Unit3TextBox.Text & "','" & Price_Unit4TextBox.Text & "','" & Price_Unit5TextBox.Text & "','" & Price_Unit6TextBox.Text & "','" & Sub_TotalTextBox.Text & "','" & VATTextBox.Text & "','" & Previous_BalTextBox.Text & "','" & Net_TotalTextBox.Text & "');"

    Using connection As SqlConnection = New SqlConnection(strConnection)
        Dim command As SqlCommand = New SqlCommand(strTreatment_price, connection)
        Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from Patient_Payment_info", connection)
        Dim ds As GUU_PATIENT_RECORDDataSet = New GUU_PATIENT_RECORDDataSet
        da.Fill(ds.Patient_Payment_Info)
        Patient_Payment_InfoDataGridView.DataSource = ds.Tables(0)
        connection.Open()
        command.ExecuteNonQuery()
        MsgBox("Record Successfully Validated.")
    End Using

1 个答案:

答案 0 :(得分:0)

按照以下步骤操作。




  1。打开控制面板。
 2。搜索服务。
 3。从搜索结果
 4打开本地服务窗口。重新启动MSSQLSERVER服务。