Loading

.net

2 posts / 0 new
Last post
Offline
Joined: 10/30/2009
.net

sir/madam..
i am a beginner with .net i am trying to get data from dropdown list(in which name is bound) and i want to display id in a textbox ...my table contains parameters name,id and item...
my problem is an error message "parameter name is not in the parameter oledb connection"..
can anybody help me??
thanks to all...

  1. Protected Sub ddl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1.SelectedIndexChanged
  2. Dim Conn As OleDbConnection
  3. Dim command1 As OleDbCommand
  4.  
  5. Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator.HOME\My Documents\Visual Studio 2008\WebSites\production\otentry.mdb;")
  6.  
  7. command1 = New OleDbCommand("SELECT * FROM [ofotentry] WHERE ([@name]) ='" & ddl1.SelectedItem.Text & "'", Conn)
  8.  
  9.  
  10. command1.Parameters("@name").Value = ddl1.SelectedItem.Text
  11. Conn.Open()
  12. command1.ExecuteNonQuery()
  13. If Not IsDBNull(command1.Parameters("@name").Value) Then
  14.  
  15.  
  16. TextBox2.Text = command1.Parameters("@tid").Value
  17. End If
  18. Conn.Close()
  19. End Sub
admin's picture
Online
Joined: 11/14/2008
re: .net

This is not the best way to get an ID from ComboBox.

Try this code:

Add this in the Load event of your form

  1. With ComboBox1
  2. .DataSource = Me.YourDataSet.ofotentry
  3. .DisplayMember = "Name"
  4. .ValueMember = "tID"
  5. End With
  6.  
  7. ComboBox1.SelectedIndex = 0

This assumes that the name of your combobox is ComboBox1

  1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  2.  
  3. If Me.ComboBox1.SelectedIndex >= 0 Then
  4. TextBox2.Textt = ComboBox1.SelectedValue.ToString
  5. End If
  6. End Sub
  7. </vbnet

Pages

Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.