Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
fredong
Yak Posting Veteran
80 Posts |
Posted - 2004-07-22 : 10:57:23
|
I am a new VB user and trying to find out how can I match the VB (for example txtShipmentnos) user input with my database tsoshipment.trannoand then return the trackingnos is also in the tsoshipment table and display it on a Label. below is my syntax and also should I need to Delcare something to get my dataview(DV) on the Button Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tranno as --How can get row from Dataview? If txtShipmentnos.Text = tranno ?? MessageBox.Show(myDV.Find("ShipTrackno"))??? Else MessageBox.Show("Wrong Shipment nos") End If End Sub--Thanks.k |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-07-22 : 12:15:12
|
I think this will work (it would work for a dataset)If txtShipmentnos.Text = DataView.Tables(0).Rows(0)("MyFieldNameHere")Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
fredong
Yak Posting Veteran
80 Posts |
Posted - 2004-07-22 : 12:29:39
|
I don't know what wrong with my code my if statemnt does not seem have a logic. can you kindly look at the Button1_Click which i tried to retrieve the data from tsoshipment.shipTracknos and display it on the label. Put an --> sign if you make changes.Thank you very much 'Import Data, Oledb, and DBNull namespacesImports System.DataImports System.Data.SqlClientPublic Class Form1 Inherits System.Windows.Forms.Form 'Declare Objects Dim myConnection As SqlConnection = New _ SqlConnection("server = localhost; database = sales;" & _ "uid = sa; pwd = thanks;") Dim myAdapter As SqlDataAdapter = New SqlDataAdapter( _ "Select tranno, shiptrackno from tsoshipment", myConnection) Dim myDS As DataSet Dim myDV As DataView Private Sub FillDataSetAndView() 'Initialize a new instance of the DataSet object... myDS = New DataSet 'Fill the DataSet object with data ... myAdapter.Fill(myDS, "tsoshipment") 'Set the DataView object to the DataSet object .. myDV = New DataView(myDS.Tables("tsoShipment")) End Sub Private Sub BindFields() 'Clear any previous bindings txtshipmentnos.DataBindings.Clear() lblTrackingsnos.DataBindings.Clear() txtNewtrackingsnos.DataBindings.Clear() 'Add new bindings to the datView objects txtshipmentnos.DataBindings.Add("Text", myDV, "tranno") txtNewtrackingsnos.DataBindings.Add("Text", myDV, "shipTrackno") End Sub#Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents txtshipmentnos As System.Windows.Forms.TextBox Friend WithEvents btnChange As System.Windows.Forms.Button Friend WithEvents txtNewtrackingsnos As System.Windows.Forms.TextBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents lblTrackingsnos As System.Windows.Forms.Label <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button Me.txtshipmentnos = New System.Windows.Forms.TextBox Me.Label1 = New System.Windows.Forms.Label Me.lblTrackingsnos = New System.Windows.Forms.Label Me.btnChange = New System.Windows.Forms.Button Me.txtNewtrackingsnos = New System.Windows.Forms.TextBox Me.Label2 = New System.Windows.Forms.Label Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(120, 144) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(96, 23) Me.Button1.TabIndex = 0 Me.Button1.Text = "&OK" ' 'txtshipmentnos ' Me.txtshipmentnos.Location = New System.Drawing.Point(120, 72) Me.txtshipmentnos.Name = "txtshipmentnos" Me.txtshipmentnos.TabIndex = 1 Me.txtshipmentnos.Text = "" ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Location = New System.Drawing.Point(8, 72) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(102, 16) Me.Label1.TabIndex = 2 Me.Label1.Text = "Enter shipment nos" ' 'lblTrackingsnos ' Me.lblTrackingsnos.Location = New System.Drawing.Point(120, 104) Me.lblTrackingsnos.Name = "lblTrackingsnos" Me.lblTrackingsnos.TabIndex = 3 ' 'btnChange ' Me.btnChange.Location = New System.Drawing.Point(392, 144) Me.btnChange.Name = "btnChange" Me.btnChange.Size = New System.Drawing.Size(96, 23) Me.btnChange.TabIndex = 4 Me.btnChange.Text = "&Change" ' 'txtNewtrackingsnos ' Me.txtNewtrackingsnos.Location = New System.Drawing.Point(392, 72) Me.txtNewtrackingsnos.Name = "txtNewtrackingsnos" Me.txtNewtrackingsnos.TabIndex = 5 Me.txtNewtrackingsnos.Text = "" ' 'Label2 ' Me.Label2.AutoSize = True Me.Label2.Location = New System.Drawing.Point(256, 72) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(125, 16) Me.Label2.TabIndex = 6 Me.Label2.Text = "Enter New Tracking nos" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(544, 485) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.txtNewtrackingsnos) Me.Controls.Add(Me.btnChange) Me.Controls.Add(Me.lblTrackingsnos) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.txtshipmentnos) Me.Controls.Add(Me.Button1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub#End Region Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' txtshipmentnos.Add("Shipment nos") FillDataSetAndView() BindFields() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If txtshipmentnos.Text = myDV.tables(0).Rows(0)("ShipTrackno") Then 'If shipnos = txtshipmentnos.Text Then myDV.Find(lblTrackingsnos.Text) Else MessageBox.Show("Wrong Shipment nos") End If End Sub Protected Overrides Sub Finalize() MyBase.Finalize() End SubEnd Classk |
 |
|
|
|
|
|
|