PDA

View Full Version : اشکال در کدنویسی پایگاه داده



mary62
دوشنبه 29 مرداد 1386, 11:46 صبح
Imports System.Data.SqlClient
Public Class FrmMain
Public Com1 As New SqlClient.SqlCommand
Public Com2 As New SqlClient.SqlCommand
Public Com3 As New SqlClient.SqlCommand
Public Com4 As New SqlClient.SqlCommand
Public datadaptor As New SqlClient.SqlDataAdapter



Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click
'Dim j As Integer
Try
If Me.txtFileID.Text <> " " Then
Me.SqlSelectCommand1.CommandText = "Select* From Patient Where" & _
"File_ID='" & txtFileID.Text & "'"
Me.PatientTableAdapter.Fill(Me.DataSet11.Patient)
For i As Integer = 0 To Me.DataGridView1.Rows.Count
If (Me.DataGridView1.Item(0, i).Value = txtFileID.Text) Then
Me.DataGridView1.Rows(i - 1).Selected = True
End If
Next
End If
Catch ex As Exception
MessageBox.Show("Erro")
End Try
End Sub

Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DataSet11.Patient' table. You can move, or remove it, as needed.
Me.PatientTableAdapter.Fill(Me.DataSet11.Patient)

End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

Try
If (Me.txtFName.Text = " " AndAlso Me.txtLName.Text = "" AndAlso Me.txtTel.Text = "") Then
MessageBox.Show("اطلاعات کلیه فیلدها را پرکنید", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Com1.CommandText = "INSERT INTO Patient(File_ID," & _
" LastName, FirstName, PhoneNumber, Adress, Note, [Special_ Illness])" & _
"VALUES('" & txtFileID.Text & " ' ," & _
"'" & txtLName.Text & " ' , " & _
"'" & txtFName.Text & "' , " & _
"'" & txtTel.Text & "' , " & _
"'" & txtAdr.Text & "' , " & _
"'" & txtEtc.Text & "' , " & _
"'" & Txtillness.Text & "')"
Me.PatientTableAdapter.GetData()
Me.datadaptor.Fill(Me.DataSet11.Patient)
Me.DataSet11.AcceptChanges()
Me.datadaptor.InsertCommand = Com1
Me.DataGridView1.DataSource() = DataSet11
Me.DataGridView1.Update()
End If
Catch ex As Exception

MessageBox.Show("Error", "E", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

Private Sub RdiBtn1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RdiBtn1.CheckedChanged
Dim SearchForm As New Form

SearchForm.Show()



End Sub


End Class

mary62
دوشنبه 29 مرداد 1386, 11:53 صبح
سلام یادم رفت بگم که از 2005 استفاده می کنم و مشکلم اینه که به روز رسانی بعد از اضافه کردن رکورد انجام نمی شود.در واقع یک سری از اطلاعات از textBox خوانده می شود و به DB باید insert بشود

پویا
دوشنبه 29 مرداد 1386, 12:52 عصر
شما چرا لقمه رو دور سرت چرخوندی
شما که دستورت رو تو sqlCommand به صورت کامل ریختی فقط کافیه اجراش کنی



com1.connction = mycon
com1.ExecuteNonQuery