Using VB.NET

I am using Combobox, when i select the value in combobox, the date value should display in datetimepicker where date = combobox id

vb6 code

cmd.CommandText = "select distinct Name from T_Person where personid = '" & txtno & "'"
Set rs = cmd.Execute
While Not rs.EOF
   If Not IsNull(rs("Name")) Then
txtName.Text = rs("Name")
       rs.MoveNext
    End If
Wend

txtno - combobox, txtname = datetimepicker1

The above code is working in vb6, But am new to vb.net

How to modify my code in vb.net

Need vb.net code help

Recommended Answers

All 4 Replies

Dim myDA As New OleDbDataAdapter
            
            myCmd.CommandText = "select distinct Name from T_Person where personid = '" & txtno & "'"
            myDA.SelectCommand = myCmd
            myDR = myCmd.ExecuteReader()
            While (myDR.Read())
                    myDR("Name"))
            End While

I dont understand the need for a loop to assign control values when only a single value can be displayed in the textbox and datepicker at a time. Also Im a bit confused by the naming conventions, a prefix for txt for a datepicker and your saying your looking for a date but the select statement shows your querying a field named "Name".

I have the same problem I am trying to read distinct values from an Access table but i get a syntax error. heres my code . The Code works fine until I put in the distinct key word.

sql = "SELECT DISTINCT Model,Make,Problem,HP FROM Makes"

can anyone point me in the right direction.

thanks
james

Your SQL syntax is invalid. Typically you use Distinct() on a single column. I'm not sure if this is the exact syntax with Access but this is how it would work in MSSQL:

Select Model, Make, Problem, HP
From Makers
Group By Model, Make, Problem, HP
Order By Model, Make, Problem, HP --This is an optional ordering line

It should be similar for access.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.