can anyone help me to write the code to get a field from database using combobox and that should display the corresponding record in datagrid using vb6.0
how to get data from database using combobox
Collapse
X
-
-
As you have posted a question in the articles section it is being moved to Visual Basic Forum
MODERATOR. -
1 Question, Are you Using ADODC Object or ADODB?Originally posted by rashmirajcan anyone help me to write the code to get a field from database using combobox and that should display the corresponding record in datagrid using vb6.0
Lets Say that your using ADODC, Just download my attachment.
1 thing, open it On your Desktop. if Error, just establish the connection again of the ADODC Object.
Regards
ErvinAttached FilesComment
-
Originally posted by jrtox1 Question, Are you Using ADODC Object or ADODB?
Lets Say that your using ADODC, Just download my attachment.
1 thing, open it On your Desktop. if Error, just establish the connection again of the ADODC Object.
Regards
Ervin
thanks a lot.......... thats what exactly i needed.....Comment
-
Originally posted by rashmirajthanks a lot.......... thats what exactly i needed.....
but i have one more problem..if i select id(which is in autonumber)in combobox it displays the corresponding records from database.. but not for strings... how to write the code to select the string in combobox.......Comment
-
Lets just base to the sample i gave.Originally posted by rashmirajbut i have one more problem..if i select id(which is in autonumber)in combobox it displays the corresponding records from database.. but not for strings... how to write the code to select the string in combobox.......
we do have the line code as follows
sql = "SELECT * FROM sample WHERE ID=" & Combo1.Text & ""
That line was used to determine the "Number or Autonumber" data type
to determine the string just put a sigle qoute( ' ) after equal ( =) sign and before last the qoute. now it will become
sql = "SELECT * FROM sample WHERE ID='" & Combo1.Text & "'"
Regards
ErvinComment
-
i have used the code for strings but it doesn't display the string in combobox and in datagrid... i have created database in which the columns are name,Course,Cou rse duration and etc....Originally posted by jrtoxLets just base to the sample i gave.
we do have the line code as follows
sql = "SELECT * FROM sample WHERE ID=" & Combo1.Text & ""
That line was used to determine the "Number or Autonumber" data type
to determine the string just put a sigle qoute( ' ) after equal ( =) sign and before last the qoute. now it will become
sql = "SELECT * FROM sample WHERE ID='" & Combo1.Text & "'"
Regards
Ervin
i hv written code like
sql = "SELECT * FROM mytable WHERE Name='" & Combo1.Text & "'"
the name column in combobox and datagrid is empty.... and also the names are deleted in database....... . plz suggest me what to do for this?Comment
-
Originally posted by rashmiraji have used the code for strings but it doesn't display the string in combobox and in datagrid... i have created database in which the columns are name,Course,Cou rse duration and etc....
i hv written code like
sql = "SELECT * FROM mytable WHERE Name='" & Combo1.Text & "'"
the name column in combobox and datagrid is empty.... and also the names are deleted in database....... . plz suggest me what to do for this?
Hello,
Does it Gives a Runtime or Not?
Is there any Records in your database?Comment
-
Originally posted by jrtoxHello,
Does it Gives a Runtime or Not?
Is there any Records in your database?
its not giving any runtime...recor ds are there in database & if i select "all" in combobox it displays the data except name,if i select any perticular name in combobox the whole columns in datagrid will become empty..
my code is :
Dim sql As String
Private Sub Combo1_Click()
If Combo1.Text = "All" Then
sql = "SELECT * FROM mytable"
Else
sql = "SELECT * FROM mytable WHERE Name= '" & Combo1.Text & "'"
End If
Adodc1.CommandT ype = adCmdText
Adodc1.RecordSo urce = sql
Adodc1.Refresh
Set DataGrid1.DataS ource = Adodc1
End Sub
Private Sub Form_Load()
'Loading Data from database to your Combo box
sql = "SELECT * FROM mytable"
'Adodc1.Refresh
Adodc1.CommandT ype = adCmdText
Adodc1.RecordSo urce = sql
Adodc1.Refresh
While Not Adodc1.Recordse t.EOF
Combo1.AddItem Adodc1.Recordse t("Name")
Adodc1.Recordse t.MoveNext
Wend
Combo1.AddItem "All"
Set DataGrid1.DataS ource = Adodc1
End SubComment
-
ReDownload and Run the programOriginally posted by rashmirajits not giving any runtime...recor ds are there in database & if i select "all" in combobox it displays the data except name,if i select any perticular name in combobox the whole columns in datagrid will become empty..
my code is :
Dim sql As String
Private Sub Combo1_Click()
If Combo1.Text = "All" Then
sql = "SELECT * FROM mytable"
Else
sql = "SELECT * FROM mytable WHERE Name= '" & Combo1.Text & "'"
End If
Adodc1.CommandT ype = adCmdText
Adodc1.RecordSo urce = sql
Adodc1.Refresh
Set DataGrid1.DataS ource = Adodc1
End Sub
Private Sub Form_Load()
'Loading Data from database to your Combo box
sql = "SELECT * FROM mytable"
'Adodc1.Refresh
Adodc1.CommandT ype = adCmdText
Adodc1.RecordSo urce = sql
Adodc1.Refresh
While Not Adodc1.Recordse t.EOF
Combo1.AddItem Adodc1.Recordse t("Name")
Adodc1.Recordse t.MoveNext
Wend
Combo1.AddItem "All"
Set DataGrid1.DataS ource = Adodc1
End SubAttached FilesComment
-
if i run your project it works but for my project ,for same code again am getting same problem.... when i run your project am getting an alert msg like"unable to bind to field or data member" if i click "ok",then it works.. my dos is windows xp and data base is ms access..Originally posted by jrtoxReDownload and Run the programComment
-
Originally posted by rashmirajif i run your project it works but for my project ,for same code again am getting same problem.... when i run your project am getting an alert msg like"unable to bind to field or data member" if i click "ok",then it works.. my dos is windows xp and data base is ms access..
How could it be,
Attach your project, let me see it.
and i tell you what to do.
Important:
i will not d coding, you will be the one who apply in your coding.
Regards
Phils ErvinComment
-
ok this is my projectOriginally posted by jrtoxHow could it be,
Attach your project, let me see it.
and i tell you what to do.
Important:
i will not d coding, you will be the one who apply in your coding.
Regards
Phils ErvinAttached FilesComment
Comment