0

I have 1 Table Called "Menu" there are some textboxes and a combobox.
I want to fill data in the Textbox called "Menu_Rate" on Selection of combobox selected item & coressponding rate of the Menu shoud be displayed in the textbox.

This is my Code

con.ConnectionString = "Data Source=localhost;Integrated Security=true;Initial Catalog=Restaurant"
        cmd.CommandText = "select Menu_Rate from Menu where Menu_Name='" & cbMenu.SelectedItem & "'"
        cmd.Connection = con
        da.SelectCommand = cmd
        con.Open()
        da.Fill(ds, "Menu")
        con.Close()
        con.Dispose()
        cmd.Dispose()

        TxtRate.Text = ds
    End Sub

Edited by bhavan kamble: n/a

5
Contributors
10
Replies
39
Views
5 Years
Discussion Span
Last Post by bhavan kamble
Featured Replies
  • You will want to create a data table form the database. Then you will use the selected index of the combobox to pull from the datatable. Example... Select Case cbMenu.SelectedItem Case 1 TxtRate.Text = dt.Rows(0).Column(1) ...... This will get the value stored in the second column of the corrosponding table … Read More

  • I am sorry...... I meant..... [CODE] TxtRate.Text = dt.Rows(0).Item(1) [/CODE] Read More

  • Have you tried the .ToString() function? Example... [CODE] TxtRate.Text = dt.Rows(0).Item(1).ToString [/CODE] Read More

  • [QUOTE=bhavan kamble;1739263]Tried...... But it shows 'DataSource' is not a member of 'System.Windows.Forms.TextBox' 'DisplayMember' is not a member of 'System.Windows.Forms.TextBox'. But Thanxx..... Please Help .... I hv to submit My Project In Next week....[/QUOTE] Hi bhavan kamble! I've tryed to fill a textbox which was dependent on a combobox choice.. what … Read More

1

You will want to create a data table form the database.


Then you will use the selected index of the combobox to pull from the datatable.

Example...

Select Case cbMenu.SelectedItem

Case 1
TxtRate.Text = dt.Rows(0).Column(1)
......


This will get the value stored in the second column of the corrosponding table row.

Assuming the value is in the second column of the same table.

0

thanxx

But it showing error as......

Value of type 'System.Data.DataRow' cannot be converted to 'System.Windows.Forms.TextBox'.

0

But it is showing the same error...

i changed My code to this......

Private Sub cbMenu_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbMenu.SelectedIndexChanged
        Dim tem As String
       [U] tem = cbMenu.SelectedItem[/U]
        con.ConnectionString = "Data Source=localhost;Integrated Security=true;Initial Catalog=Restaurant"
        cmd.CommandText = "select Menu_Rate from Menu where Menu_Name='" & tem & "'"
        cmd.Connection = con
        da.SelectCommand = cmd
        con.Open()
        da.Fill(ds, "Menu")
        con.Close()
        con.Dispose()
        cmd.Dispose()
        Dim row As DataRow

        For Each row In ds.Tables("Menu").Rows
            TxtRate.Text &= row("Menu_Rate") & " "
        Next
    End Sub

Now The error is in the underlined part..

it shows...
Conversion from type 'DataRowView' to type 'String' is not valid.

0

sorry i give the code for integers, not string. :P

don't know how to delete post

Edited by steplar: wrong code

1

Have you tried the .ToString() function?

Example...

TxtRate.Text = dt.Rows(0).Item(1).ToString

Edited by Begginnerdev: n/a

0

Have you tried the .ToString() function?

Example...

TxtRate.Text = dt.Rows(0).Item(1).ToString

Try this...

Dim conn As New SqlConnection(ConnectionString)
        Dim abc As String
        abc= cbMenu.Text 'the value selected in combo box       
        Dim strSQL As String = "select Menu_Rate from Menu where Menu_Name='" & abc & "'"
        Dim da As New SqlDataAdapter(strSQL, conn)
        Dim ds As New DataSet
        da.Fill(ds, "Menu")
        With txtRate ' your text box name
            .DataSource = ds.Tables("Menu") 'your table name            
            .DisplayMember = "Menu_Rate"
          '  .ValueMember = "ProductID"
        End With

Edited by poojavb: n/a

0

Tried......

But it shows

'DataSource' is not a member of 'System.Windows.Forms.TextBox'

'DisplayMember' is not a member of 'System.Windows.Forms.TextBox'.

But Thanxx.....

Please Help .... I hv to submit My Project In Next week....

2

Tried......

But it shows

'DataSource' is not a member of 'System.Windows.Forms.TextBox'

'DisplayMember' is not a member of 'System.Windows.Forms.TextBox'.

But Thanxx.....

Please Help .... I hv to submit My Project In Next week....

Hi bhavan kamble!

I've tryed to fill a textbox which was dependent on a combobox choice.. what i did was this:

conn.ConnectionString = ("Data Source=Laptop-VAIO\SQLEXPRESS;Initial Catalog=AMR;Integrated Security=True")
txtState.Clear()
        txtState.Enabled = True

        '-------------------------------Fill txtState-----------------------------

        Dim StateTable As New DataTable
        StateTable.Clear()
        Dim sqlCmd As New SqlCommand("select DISTINCT State_LCL from T_MUNICIPALITY,T_MUNICIPALITY_STREETS1 where  T_MUNICIPALITY.Municipality_LCL=T_MUNICIPALITY_STREETS1.Municipality_LCL and T_MUNICIPALITY_STREETS1.Municipality_LCL='" & cboMunicipality.Text & "'", conn)
        conn.Close()
        Dim result As String
        Try
            conn.Open()
            result = sqlCmd.ExecuteScalar()

            If result IsNot Nothing Then
                txtState.Text = result.ToString()
                'MessageBox.Show(txtState.Text)
            End If
        Catch ex As SqlException
            MessageBox.Show(ex.Message)
        Finally
        End Try

I wish I helped!

0

Thanxxx....... yaarrrr, thank you so much....

Its done......
Thanxx....for your valuable......time.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.