473,385 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Textbox lookup through ComboBox

Hey I am trying to create a textbox that relays text to my combobox on my for so I may lookup details in my DB but I get two errors . . .First there is a Primary Key error, "Table does not have a primary key" and if I do it the other way around by asking my textbox alone to lookup my values that I put in I seem to receive the same values regardless of what I put in my texbox. . . Please review these different codes and see if anyone can spot my mistake. . . Replies would be greatly appreciated.

TEXTBOX LOOKUP CODE:
Expand|Select|Wrap|Line Numbers
  1. Private m_cnADONetConnection As New OleDb.OleDbConnection()
  2. Private m_daDataAdapter As OleDb.OleDbDataAdapter
  3. Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
  4. Private m_dtCD As New DataTable
  5. Dim m_rowPosition As Integer = 0
  6.  
  7. Private Sub StockDetailsForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  8.    m_cnADONetConnection.ConnectionString = _
  9. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TEST.mdb"
  10.  
  11.    m_cnADONetConnection.Open()
  12.  
  13.    m_daDataAdapter = New OleDb.OleDbDataAdapter("Select * From CD", m_cnADONetConnection)
  14.    m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)
  15.    m_daDataAdapter.Fill(m_dtCD)
  16.  
  17.  
  18. Public Sub StockCheck()
  19.  
  20. StockEdit_Open_Conn()
  21. Dim sql = "SELECT CouplingCode ,AlbumTitle ,ReleaseDate ,TotalSongs ,PPD FROM CD WHERE CouplingCode='" & StockDetailsForm.txtSearch.Text & "'"
  22. Dim cmd As New System.Data.OleDb.OleDbCommand
  23.  
  24. cmd = New OleDbCommand(sql, m_cnADONetConnection)
  25. Dim exReader As OleDbDataReader = cmd.ExecuteReader
  26. m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)
  27.  
  28.  
  29. Private Sub txtSearch_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Leave
  30.  
  31. Try
  32. If exReader.Read = False Then
  33. MessageBox.Show("Stock Item does not exist", "Stock Item Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
  34. m_cnADONetConnection.Close()
  35. m_cnADONetConnection.Dispose()
  36. Else
  37. StockDetailsForm.CouplingCodeID.Text = _
  38. m_dtCD.Rows(m_rowPosition)("CouplingCode").ToString()
  39. StockDetailsForm.txtAlbumName.Text = _
  40. m_dtCD.Rows(m_rowPosition)("AlbumTitle").ToString()
  41. StockDetailsForm.txtPPD.Text = _
  42. m_dtCD.Rows(m_rowPosition)("PPD").ToString()
  43. StockDetailsForm.txtTotalSongs.Text = _
  44. m_dtCD.Rows(m_rowPosition)("TotalSongs").ToString()
  45. StockDetailsForm.dtpReleaseDate.Text = _
  46. m_dtCD.Rows(m_rowPosition)("ReleaseDate").ToString()
  47. StockDetailsForm.txtQtyHand.Text = _
  48. m_dtCD.Rows(m_rowPosition)("QtyOnHand").ToString()
  49. End If
  50. End Sub 
  51.  
TEXTBOX TO COMBOBOX LOOKUP CODE :
Expand|Select|Wrap|Line Numbers
  1.     Private m_cnADONetConnection As New OleDb.OleDbConnection
  2.     Private m_daDataAdapter As OleDb.OleDbDataAdapter
  3.     Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
  4.     Private m_dtCD As New DataTable
  5.     Dim m_rowPosition As Integer = 0
  6.  
  7.     Private Sub NewEditCDForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8.         m_cnADONetConnection.ConnectionString = _
  9.         "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TEST.mdb"
  10.  
  11.         m_daDataAdapter = New OleDb.OleDbDataAdapter("Select * From CD", m_cnADONetConnection)
  12.         m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)
  13.         m_daDataAdapter.Fill(m_dtCD)
  14.  
  15.         m_cnADONetConnection.Open()
  16.     End Sub
  17.  
  18.     Private Sub txtSearch_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Leave
  19.         Try
  20.             CDLookup.Text = txtSearch.Text
  21.             CDLookup.Text = _
  22.             m_dtCD.Rows.Find("CouplingCode").ToString()
  23.  
  24.             Dim sql = "SELECT * FROM CD WHERE CouplingCode='" & txtSearch.Text & "'"
  25.             Dim cmd As New System.Data.OleDb.OleDbCommand
  26.             cmd = New OleDbCommand(sql, m_cnADONetConnection)
  27.             Dim exReader As OleDbDataReader = cmd.ExecuteReader
  28.  
  29.  
  30.             If exReader.Read = False Then
  31.  
  32.                 MessageBox.Show("Invalid Username and/or Password. . . ", "Authentication Has Faild", MessageBoxButtons.OK, MessageBoxIcon.Stop)
  33.  
  34.             Else
  35.                 CouplingCodeID.Text = _
  36.                 m_dtCD.Rows.Find(m_rowPosition)("CouplingCode").ToString()
  37.                 Exit Sub
  38.             End If
  39.         Catch ex As Exception
  40.             MsgBox(ex.Message)
  41.         End Try
  42.     End Sub
Jan 17 '10 #1
1 1438
mzmishra
390 Expert 256MB
Did you try to debug and see what value you are getting as textbox text.I think it is somehow set to some default or initial value
Jan 19 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: my-wings | last post by:
I've been reading about how evil Lookup fields in tables are, but I've got to be missing something really basic. I know this subject has been covered before, because I've just spent an hour or two...
1
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! Can any one point me in direction of modify a TextBox control. What i want to do is to add a button, like the ComboBox have. with my own bitmap and execute an Event when clicked. I...
2
by: Mamatha | last post by:
Hi I want to add an icon to the textbox's text. I don't know how to display icon in textbox in VB.NET. If any one knows please let me know. Thanks in advance. Mamatha
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
3
by: Patrick [MSFT] | last post by:
Let me preface this with the goal I'm trying to achieve is mimic a feature of another language (Dexterity used by Microsoft Dynamics) and so while a filling a drop down list is a workable solution...
0
by: =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?= | last post by:
Hi, I have a value that represents a FunctionID that gets sent (in the querystring) to a page. When loading this page I need to display the corresponding FunctionName for that FunctionID in a...
3
by: Richard | last post by:
How is the result of query placed in a unbound textbox ? Suppose CriteriaLookups has columns TableName, KeyColumn, KeyValue, DataColumn Foo,x,11,xhat Bar,z,3,xyzzy And
4
gcoaster
by: gcoaster | last post by:
Hello! I have a dilemma I have a form that is bound to a table = tblCALLDETAILS I have a field in the table that is on the the form called = email, that is a textbox txtClientEmail ...
14
by: Mark | last post by:
I have a table with a field that uses a combobox to populate values. The Lookup tab within table design mode is the following: Display Control Combo Box Row Source Type ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.