2016-03-28 25 views
0

Ben oldukça yeni VB için yeni ve kod satır yazdım ama her zaman ben programı çalıştırınHata almaya devam ediyorum: 40 SQL veritabanı içine veri girişi kaydetmeye çalışırken bir düğmeye tıklama ile oluşturulan bir düğme

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

almaya devam burada kod

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 ifadeleri oluşturmanın doğru yolu bu değil. Burada en az miktarda araştırma SQL Parametrelerini nasıl ve neden kullanacağınızı gösterecektir – Plutonix

+0

Burada çok fazla sorun var: 1) Boşluklu alanların köşeli parantez içine alınması gerekir _ [Hasta Adresi] _ 2) YANLıŞ birleştirilmiş dizgileri kesin ve bunun yerine Parametreli Sorgular 3) Insert Into deyimi SqlCommand.ExecuteNonQuery yöntemi kullanılarak yürütülür. – Steve

cevap

0

benim hatları aşağıdaki adımları takip olduğunu.

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

tamam teşekkürler, ama bana nasıl parametrelendirileceği hakkında bir fikir verebilir misin? – Chinedu

İlgili konular