Click here to Skip to main content
16,019,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I have created a small vb.net program.

I need to retrieve data from sql by vb.net and modify it but when I run it, it returns with the first record at sql table.

That means the query is not executed.
Can you please check this code and give me a solution

Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

Public Class main

    Private sqlconn As New SqlConnection("Data Source=MODY-PC;Initial Catalog=Sosa;User ID=sa;Password=password123")
    Private da As New SqlDataAdapter("SELECT * from EM_TBL", sqlconn)
    Private coomd As New SqlCommand("SELECT * from EM_TBL Where EM_NAME =@ddd", sqlconn)
    Private ds As New DataSet
    Private cmb As New SqlCommandBuilder(da)
    Private cmd As New SqlCommand


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
        Login_Form.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ''search button


        Try
            coomd.Parameters.AddWithValue("@ddd", TextBox1.Text)
            da.Fill(ds, "EM_TBL")
            TextBox3.DataBindings.Add("text", ds, "EM_TBL.EM_NAME")
            TextBox2.DataBindings.Add("text", ds, "EM_TBL.EM_MID_NA")
            TextBox4.DataBindings.Add("text", ds, "EM_TBL.EM_LAST")
            TextBox5.DataBindings.Add("text", ds, "EM_TBL.JOP")
            TextBox6.DataBindings.Add("text", ds, "EM_TBL.ID_NO")
            TextBox7.DataBindings.Add("text", ds, "EM_TBL.PASS_NO")
            TextBox8.DataBindings.Add("text", ds, "EM_TBL.PASS_DATE")
            TextBox9.DataBindings.Add("text", ds, "EM_TBL.RES_EXP_DATE")
            TextBox10.DataBindings.Add("text", ds, "EM_TBL.NATIONALITY")
            TextBox11.DataBindings.Add("text", ds, "EM_TBL.MOB1")
            TextBox12.DataBindings.Add("text", ds, "EM_TBL.MOB2")
            TextBox13.DataBindings.Add("text", ds, "EM_TBL.HOME_NO")
            TextBox14.DataBindings.Add("text", ds, "EM_TBL.ADDRESS")
            TextBox15.DataBindings.Add("text", ds, "EM_TBL.COMMENT")
            sqlconn.Close()
        Catch ex As Exception

        End Try
    End Sub
Posted
Updated 15-Jan-11 21:32pm
v2

my friend
i search for parameter and i need to return with only searched raw
plz help me
 
Share this answer
 
Couple of things:
1) You don't appear to open "sqlconn".
2) You don't bother to use the exception: it may give you valuable information as to what the problem is. At the minimum, log it somewhere and look at it.
3) What did you expect a TextBox DataBinding to do? Other than show the first record in the dataset? Read your mind at run time and display only record you first thought of? Does a TextBox normally show data for more than one record?

If you stop playing with TextBoxes and use a control capable of more complex databinding, you may get the results you want...

(There is a basics article here: Data binding concepts in .NET windows forms[^])
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900