1 Replies - 5263 Views - Last Post: 28 January 2009 - 09:04 AM Rate Topic: -----

#1 bhati  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-January 09

how to transfer data from flexgrid to the database

Posted 28 January 2009 - 12:57 AM

Public rsRecCat As New ADODB.Recordset
Public nIndx As Integer
Public rsPatRecDet As New ADODB.Recordset
Dim i, j As Integer
Dim rsPat As New ADODB.Recordset

Private Sub chkRecCat_Click(Index As Integer)
	
	rsRecCat.MoveFirst
	rsRecCat.Find "Rec_Desc='" & chkRecCat(Index).Caption & "'"
	nIndx = Index
	If chkRecCat(Index).Value = 1 Then
	   frmRecVal.Show vbModal
	Else
	
	
	End If
End Sub
Private Sub cmdCancel_Click()
	If sAdd = "" Then
	   Call funEnabCmd(False, True, True, True, True, False, False)
	   Call funDisplay
	Else
	   rsRecCat.CancelUpdate
	   rsRecCat.Requery
	   If rsRecCat.EOF And rsRecCat.BOF Then
			lblItemIdVal.Caption = ""
			txtItemDesc.Text = ""
			txtMaxlimit.Text = ""
			txtMinlimit.Text = ""
			Call funEnabCmd(False, False, True, False, False, False, False)
	Else
			Call funEnabCmd(False, True, True, True, True, False, False)
			Call funDisplay
	   End If
	End If
End Sub
Private Sub cmdExit_Click()
	'Insert records in to the table
	On Error GoTo lblError
	Dim iNo As Integer
	Dim sSql As String
	If rsPatRecDet.State = 1 Then rsPatRecDet.Close
	rsPatRecDet.Open "select * from Tab_Pat_Rec_Grade_Details where Reg_No =" & frmPatientMaster.txtRegNo.Text, cndb, adOpenDynamic, adLockOptimistic
	If rsPatRecDet.EOF And rsPatRecDet.BOF Then
		For iNo = 1 To flgRecDet.Rows - 2
			   flgRecDet.Row = iNo
			   rsPatRecDet.UpdateBatch
			   rsPatRecDet.AddNew
			   flgRecDet.Col = 0
			   rsPatRecDet.Fields("Sr_No") = Val(flgRecDet.Text)
			   flgRecDet.Col = 1
			   rsPatRecDet.Fields("Reg_No") = frmPatientMaster.txtRegNo.Text
			   flgRecDet.Col = 0
			   rsPatRecDet.Fields("Rec_Grade_ID") = Val(flgRecDet.Text)
			   'flgRecDet.Col = 3
			   rsPatRecDet.Fields("Value") = flgRecDet.Text
			'   rsPatRecDet.Update
		Next iNo
		frmPatientMaster.bRec = True
	Else
		 MsgBox "Critical Error Record already existing"
	End If
	Unload Me
	Exit Sub
lblError:
	 If Err.Number = -2147217873 Then
		MsgBox "Record all Ready Entered ", vbCritical
	Else
		End
	 End If
End Sub

Private Sub cmdSave_Click()
'For i = 0 To flgRecDet.Rows
'rsPat.Fields("Sr_No") = flgRecDet.TextMatrix(1, 0)
rsPat.Fields("Category") = flgRecDet.TextMatrix(1, 1)
'Next
'For j = 0 To flgRecDet.Col
'insert into  values flgRecDet.TextMatrix=[i,j];
'Next
'Next
			'flgRecDet.Col = 0
			'frmPatReaction.flgRecDet.Text
			'frmPatReaction.flgRecDet.Col = 1
			'frmPatReaction.flgRecDet.Text = frmPatReaction.chkRecCat(frmPatReaction.nIndx).Caption
			'frmPatReaction.flgRecDet.Col = 2
			'frmPatReaction.flgRecDet.Text = Mid$(lblRecName(iCount).Caption, InStr(lblRecName(iCount).Caption, "") + 1)
End Sub

Private Sub Form_Load()
	flgRecDet.Row = 0
	flgRecDet.Col = 0
	flgRecDet.Text = "Sr. No"
	flgRecDet.Col = 1
	flgRecDet.Text = "Category"
	flgRecDet.Col = 2
	flgRecDet.Text = "Allergy"
	'flgRecDet.Col = 3
	'flgRecDet.Text = "Grade"
	lblRecGrdIdVal.Caption = frmPatientDetails.txtName.Text
	If cndb.State = 0 Then Call funConnection
	If rsRecCat.State = 1 Then rsRecCat.Close
	rsRecCat.Open "select * from Tab_Rec_Cat_Code", cndb, adOpenStatic, adLockReadOnly
	If rsRecCat.EOF And rsRecCat.BOF Then
	   MsgBox "Critical Error ", vbCritical
	   End
	Else
	   If frmPatientDetails.sAdd = "Mod" Then
		  If rsPatRecDet.State = 1 Then rsPatRecDet.Close
		  rsPatRecDet.Open "SELECT Tab_Pat_Rec_Detail.Sr_No, Tab_Rec_Cat_Code.Rec_Desc as Category, " & _
									" Tab_Rec_Master.[Rec_Name] as Allergen" & _
									" INNER JOIN (Tab_Rec_Master INNER JOIN Tab_Pat_Rec_Details ON" & _
									" Tab_Rec_Master.Rec_ID = Tab_Pat_Rec_Details.Rec_ID) ON " & _
									" Tab_Rec_Cat_Code.Rec_Cat_Code = Tab_Rec_Master.Rec_Cat_Code " & _
									" WHERE (((Tab_Pat_Rec_Details.Reg_No)='" & frmPatientDetails.txtRegNo.Text & "'))", cndb, adOpenStatic, adLockReadOnly
		  Set dbgRecGrd.DataSource = rsPatRecDet
		  Dim rsTmp As New ADODB.Recordset
		  rsTmp.Open "SELECT distinct Tab_Rec_Cat_Code.Rec_Desc AS Category FROM Tab_Rec_Cat_Code " & _
		  " RIGHT JOIN (Tab_Rec_Master INNER JOIN Tab_Pat_Rec_Details ON " & _
		  " Tab_Rec_Master.Rec_ID = Tab_Pat_Rec_Detail.Rec_ID) ON Tab_Rec_Cat_Code.Rec_Cat_Code = Tab_Rec_Master.Rec_Cat_Code " & _
		  " WHERE (((Tab_Pat_Rec_Detail.Reg_No)='" & frmPatientDetails.txtRegNo.Text & "'))", cndb, adOpenStatic, adLockReadOnly
		  
	   End If
	   Dim nCount As Integer
	   While Not rsRecCat.EOF
			chkRecCat.Item(nCount).Caption = rsRecCat.Fields("Rec_Desc")
			chkRecCat.Item(nCount).Visible = True
			nCount = nCount + 1
			Load chkRecCat.Item(nCount)
			chkRecCat.Item(nCount).Left = chkRecCat.Item(nCount - 1).Left
			chkRecCat.Item(nCount).Top = chkRecCat.Item(nCount - 1).Top + 300
			rsRecCat.MoveNext
		Wend
			Dim iNo As Integer
			If frmPatientDetails.sAdd = "Mod" Then
				dbgRecGrd.Visible = True
				flgRecDet.Visible = False
				For iNo = 0 To nCount
					rsTmp.MoveFirst
					While Not rsTmp.EOF
						   If chkRecCat.Item(iNo).Caption = rsTmp("Category") Then chkRecCat.Item(iNo).Value = 1
						   rsTmp.MoveNext
					Wend
				Next iNo
			Else
			   dbgRecGrd.Visible = False
			   flgRecDet.Visible = True
			End If
			
		  If rsPat.State = 1 Then rsPat.Close
	rsPat.Open "select * from Tab_Pat_Rec", cndb, adOpenDynamic, adLockOptimistic
	If rsPat.EOF And rsPat.BOF Then
		Call funEnabCmd(True, False, True, False, False, True, False)
	Else
		Call funEnabCmd(True, True, True, True, True, True, False)
		'funDisplay
	End If
	End If
	
	
	
	
End Sub

Public Sub funEnabCmd(bfraMain As Boolean, bfraNav As Boolean, bAdd As Boolean, bMod As Boolean, bDel As Boolean, bSav As Boolean, bCanc As Boolean)
	framain.Enabled = bfraMain
	'fraNav.Enabled = bfraNav
	'cmdAdd.Enabled = bAdd
	'cmdModify.Enabled = bMod
	'cmdDelete.Enabled = bDel
	cmdSave.Enabled = bSav
	cmdCancel.Enabled = bCanc
End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: how to transfer data from flexgrid to the database

#2 Student_101  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 12-January 09

Re: how to transfer data from flexgrid to the database

Posted 28 January 2009 - 09:04 AM

Hi,

I have usually added values from text boxes or stuff to the database.

But I think you should also be able to do this through the flexgrid.textmatrix property

For example:

Set connection to Database
Your ADODB Connection
Your ADODB Recordset

open your recordset

do while not recordset.eof

Recrodset.Addnew

for i = 0 to msflexgrid.rows -1
Recordset!YOURFEILD1 = msflexgrid.textmatrix(i,1)
Recordset!YOURFEILD2 = msflexgrid.textmatrix(i,2)
.....
similarly for all your fields, then

Recordset.update
recordset.movenext

loop

close recordset

something like this... hope it helps :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1