C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How To bind data With the help odbc by coding


Posted Date: 28 Apr 2008    Resource Type: Code Snippets    Category: Databinding

Posted By: andy robarts       Member Level: Gold
Rating:     Points: 10



There are 2 part in below coding
1. Module code for binding data base
2. Form coding for binding tables

1. Module code


Imports System.Data.Odbc
Module Module1
Public cn As OdbcConnection
Public da As OdbcDataAdapter
Public ds As New DataSet

Dim activeprocess As String

Public Sub CreateConnection()
Try



'cn = New OdbcConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource= E:\projects\hospital mgt\HOSPITAL_ MGT.mdb")

Comment :- By DNS>
cn = New OdbcConnection("Dsn=Hospital")

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub


2. Table Binding Code In form Load


Imports System.Data
Imports System.Data.Odbc
Public Class frmNewPatientEntry
Dim databinding1, databinding2 As New BindingSource
Dim drow As DataRow
Dim FindRow As Object
Dim Odbcinput, ssql, odbcinput1 As String
Dim saction, i As Integer
Dim objDataView As New DataView
Private Sub NewPatientEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateConnection()
' Call RefreshData Procedure
Call refreshdata()
' Call BindFields Procedure
Call BindFields()
'Call BindFields1()
End Sub
Private Sub refreshdata()
'FOR PATIENT TABLE
Try
cn.Close()
If cn.State = ConnectionState.Closed Then cn.Open()
da = New OdbcDataAdapter("select * from Pati_info", cn)
ds = New DataSet
da.Fill(ds, "Pati_info")
da.Dispose()

databinding1.DataSource = ds.Tables("Pati_info") ' Binding TBLTRIAL table to data
databinding1.Sort = "Patient_ID" 'To sort and Search Record ID wise
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
' FOR RECEIPT TABLE
Try
da1 = New OdbcDataAdapter("select * from Receipt", cn)
ds1 = New DataSet
da1.Fill(ds1, "Receipt")
da1.Dispose()

databinding2.DataSource = ds1.Tables("Receipt") ' Binding TBLTRIAL table to data
databinding2.Sort = "Receipt_No" 'To sort and Search Record ID wise

cn.Close()
' Call fillcombo()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub BindFields()
Try
'FOR PATIENT TABLE
FindRow = CType(databinding1.Current, Object)
txtID.Text = FindRow("Patient_ID")
txtNM.Text = FindRow("Patient_Nm")
CBType.Text = FindRow("Patient_Type")
If CBType.Text = "Accident" Then
txtAccNo.Text = FindRow("Accident_No")
txtAccdt.Text = FindRow("Accident_D_T")
txtFIRdt.Text = FindRow("FIR_D_T")
txtFIRNo.Text = FindRow("FIR_No")
txtAccType.Text = FindRow("Accident_Type")
Else
txtAccNo.Text = ""
txtAccdt.Text = ""
txtFIRdt.Text = ""
txtFIRNo.Text = ""
txtAccType.Text = ""
End If
txtAdd.Text = FindRow("Patient_Add")
txtPh.Text = FindRow("Patient_Ph")
txtMo.Text = FindRow("Patient_Mob")
txtAge.Text = FindRow("Patient_Age")
cmbGender.Text = FindRow("Patient_Sex")
txtDOB.Text = FindRow("Patient_DOB")
DateTimePicker1.Text = FindRow("Adm_D_T")
txtRelation.Text = FindRow("Relation")
txtRespNM.Text = FindRow("Patient_Resp_Per_Nm")

' FOR RECEIPT TABLE
FindRow = CType(databinding2.Current, Object)
txtAdvPay.Text = FindRow("Adv_Pay")

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

By these 2 code Undestand the logic of Data base & Table Binding logic.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Bind DropDownList from DataBase , Using c#
Previous Resource: How to retrieve populated datatable from sql server
Return to Discussion Resource Index
Post New Resource
Category: Databinding


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use