compare with data in sql database

Hi,

i am using visual studio 2003 and sql server 2000

I have a program that connects to a database.
the database contains two colums:
example:
ProductId--Name
1----Casino Royale
2----Silent Hill
3----Lady in the Water

there is a "Form1"
when i click on a menu item on Form1, an inputbox is displayed asking the user for a productid,
what i am trying to achieve is that according to the productid a correspondent name will be displayed in another "Form2".
i already have made the connection to the database and it's working
but, i don't know how can i compare with the data in the database,

what can i do?

thanks for any response..

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
If InputBox("Enter the code:", "Product:") = ?? Then

End If
End Sub
[969 byte] By [derok] at [2007-11-20 11:53:49]
# 1 Re: compare with data in sql database
Post your code. You might want to use a SELECT statement.
dglienna at 2007-11-10 3:08:14 >
# 2 Re: compare with data in sql database
i modified the code.
In the Form1 there is a Button, a Label, and a Textbox,
according to the id entered in the Textbox, when the button is clicked, the name of the movie gets displayed in the Label, the problem now, is that when i do the operation again(click the button), the program crashes and sends an error:

No controled exception of type: 'System.ArgumentException' in system.windows.forms.dll

Two items in the collection are linking in the same property,

pointing at line:

Label1.DataBindings.Add("text", dv, "Nombre")

what can i do?

the code:


Public Class Form1
Inherits System.Windows.Forms.Form

Dim thisConnection As SqlConnection = New SqlConnection("Data Source=.;Integrated Security=SSPI;Initial Catalog=Video")

Dim sql As String = "SELECT * FROM Productos"
Dim da As New SqlDataAdapter(sql, thisConnection)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
da.Fill(DataSet1, "Products")
Dim dt As DataTable = DataSet1.Tables("Products")
Dim gt As String = TextBox1.Text

Dim dv As New DataView(dt, "IdProduct='" + TextBox1.Text + "'", "Name", DataViewRowState.CurrentRows)

Label1.DataBindings.Add("text", dv, "Name")
End Sub

End Class
derok at 2007-11-10 3:09:15 >
# 3 Re: compare with data in sql database
Here's a sample:

Private Sub DemonstrateDataView()
' Create one DataTable with one column.
Dim table As DataTable = New DataTable("table")
Dim colItem As DataColumn = New DataColumn("item", _
Type.GetType("System.String"))
table.Columns.Add(colItem)

' Add five items.
Dim NewRow As DataRow
Dim i As Integer
For i = 0 To 4

NewRow = table.NewRow()
NewRow("item") = "Item " & i
table.Rows.Add(NewRow)
Next
table.AcceptChanges()

' Create two DataView objects with the same table.
Dim firstView As DataView = New DataView(table)
Dim secondView As DataView = New DataView(table)

' Change the values in the table.
table.Rows(0)("item") = "cat"
table.Rows(1)("item") = "dog"

' Print current table values.
PrintTableOrView(table, "Current Values in Table")

' Set first DataView to show only modified versions of original rows.
firstView.RowStateFilter = DataViewRowState.ModifiedOriginal

' Print values.
PrintTableOrView(firstView, "First DataView: ModifiedOriginal")

' Add one New row to the second view.
Dim rowView As DataRowView
rowView = secondView.AddNew()
rowView("item") = "fish"
' Set second DataView to show modified versions of
' current rows, or New rows.
secondView.RowStateFilter = DataViewRowState.ModifiedCurrent _
Or DataViewRowState.Added
' Print modified and Added rows.
PrintTableOrView(secondView, _
"Second DataView: ModifiedCurrent or Added")
End Sub

Overloads Private Sub PrintTableOrView( _
ByVal view As DataView, ByVal label As String)
Console.WriteLine(label)
Dim i As Integer
For i = 0 To view.count - 1

Console.WriteLine(view(i)("item"))
Next
Console.WriteLine()
End Sub

Overloads Private Sub PrintTableOrView( _
ByVal table As DataTable, ByVal label As String)
Console.WriteLine(label)
Dim i As Integer
For i = 0 To table.Rows.Count - 1
Console.WriteLine(table.Rows(i)("item"))
Next
Console.WriteLine()
End Sub
dglienna at 2007-11-10 3:10:13 >