Hai, I have 2 question to ask about vb.net. Now i'm using Visual Studio 2005 with connection MySql...

1. how if I want to passing the data from database to the textbox by SEARCH button. I Have 1 SEARCH button and 3 textbox [txtname],[txtage],[txtaddress] and to pass it also on datagrid...

2. I have a id_Student starting with S001 in database...and I want the id is increment when new data is added. The id_Student is display using lblID_stud

Thanks in advanced. Hope anyone can help me to solve/handle this problem...

Recommended Answers

All 6 Replies

To increment the id_Student column all you needed to do was define the column as the primary key with auto increment. Assuming the id_Student is an integer data type the declaration would have been:

create table some_table(
id_Student int not null primary key auto_increment,

Now whenever new data is inserted you don't include a value for the id_Student, mySQL will increment it automatically. You can alter the increment rate if the default of 1 isn't what you need.
As for searching and displaying data from a database you'd be better off looking for a tutorial online to show you how to do that. There are many to choose from.

i have create a coding and the data is display on textox but it only display the first row data from the database.

This is my code

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        If txtSearch.Text <> "" Then

                myCommand = New MySqlCommand("SELECT id_pelajar, id_pengguna, pel_nama, pel_umur, pel_jantina, pel_alamat, pel_bangsa, pel_lain, pel_status, pel_tdaftar, pel_ic, pel_tlahir, pel_notel, pel_nofon, pel_pakej, pel_kemahiran, pel_intensif, pel_deposit, pel_bpenuh, pel_jumlah, pel_bpertama, pel_bkedua,pel_bketiga,pel_tahun,pel_sesi,pel_pengajar,pel_keputusan FROM daftarpelajar WHERE id_pelajar", conn)
                myData = myCommand.ExecuteReader()

                If myData.HasRows = txtCarian.Text Then
                    txtIDpel.Text = myData(0).ToString
                    lblPengguna.Text = myData(1).ToString
                    txtName.Text = myData(2).ToString
                    txtUmur.Text = myData(3).ToString
                    txtJantina.Text = myData(4).ToString
                    txtAlamat.Text = myData(5).ToString
                    txtBangsa.Text = myData(6).ToString
                    txtLain.Text = myData(7).ToString
                    txtStatus.Text = myData(8).ToString
                    txtTDaftar.Text = myData(9).ToString
                    txtNoIC.Text = myData(10).ToString
                    txtTLahir.Text = myData(11).ToString
                    txtTel.Text = myData(12).ToString
                    txtFon.Text = myData(13).ToString
                    txtPakej.Text = myData(14).ToString
                    txtKemahiran.Text = myData(15).ToString
                    txtIntensif.Text = myData(16).ToString
                    txtDeposit.Text = myData(17).ToString
                    txtbPenuh.Text = myData(18).ToString
                    txtJumlah.Text = myData(19).ToString
                    txtb1.Text = myData(20).ToString
                    txtb2.Text = myData(21).ToString
                    txtb3.Text = myData(22).ToString
                    txtTahun.Text = myData(23).ToString
                    txtSesi.Text = myData(24).ToString
                    txtPengajar.Text = myData(25).ToString
                    txtKeputusan.Text = myData(26).ToString
                End If
            Catch ex As System.Exception
            End Try
            MsgBox("Student ID", MsgBoxStyle.Information)
        End If

        dgCarianPelajar.Enabled = True

    End Sub


Sub dgridsource()
        myAdapter = New MySqlDataAdapter("SELECT * FROM daftarpelajar WHERE id_pelajar = ('" & Trim(txtCarian.Text) & "')", conn)
        Dim dt As New DataTable
        dgCarianPelajar.DataSource = dt
    End Sub

You can get rid of the has rows, and try:

If myData IsNot Nothing Then
   Do While myData.Read
   'Place your code here.
   'Use GetValue instead of .toString
MsgBox("Empty Reader")
End IF

i can't get it by using GetValue, could you please show me an example how to create it...still newbie in vb.net

okay,get it. i change to

txtIDpel.Text = myData.GetValue(0)
lblPengguna.Text = myData.GetValue(1)
txtName.Text = myData.GetValue(2)
txtUmur.Text = myData.GetValue(3)

thanks hericles and beginnerdev

now I have a problem to make a search by using combo box. how if I have 2 item [name], [age] and the data will show in text box. this my code but its not work

myCommand = New MySqlCommand("SELECT * FROM daftarpelajar WHERE " & cbPilihan.Text & " Like '%" & txtCarian.Text & "%' ORDER by id_pelajar ", conn)

You will have to close this thread and start a new one. I am sure we will be able to help you out.

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.