2016-03-28 15 views
0

私はVBには新しく、数行のコードを書いていますが、プログラムを実行するたびにSQLデータベースにデータエントリを保存しようとしたときに40回ボタンのクリックで作成したとき

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

これは、SQL文を作成する正しい方法ではありません。ここでの最小限の研究では、SQLパラメータの使用方法とその理由を示します – Plutonix

+0

ここに問題がたくさんあります:1)空白のフィールドは大括弧で囲む必要があります_ [Patient Address] _ 2)絶対的な文字列の連結を避け、クエリ3)Insert Into文は、SqlCommand.ExecuteNonQueryメソッドを使用して実行されます。 – Steve

答えて

0

の私の行は、以下の手順に従ってくださいです。

1. Open control panel. 
2. Search for services. 
3. Open Local services window from the search results 
4. Restart the MSSQLSERVER service. 
+0

大丈夫ですが、パラメータ化する方法を教えていただけますか? – Chinedu

関連する問題