用vb在sql上搜索 [英] search at sql by vb

查看:47
本文介绍了用vb在sql上搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我创建了一个小的vb.net程序.

我需要通过vb.net从sql检索数据并对其进行修改,但是当我运行它时,它会返回sql表中的第一条记录.

这表示查询未执行.
能否请您检查此代码并给我解决方法

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

推荐答案

事物的结合:
1)您似乎没有打开"sqlconn".
2)您不必费心使用该异常:它可以为您提供有关问题所在的有价值的信息.至少将其记录在某个地方并查看它.
3)您期望TextBox DataBinding做什么?除了显示数据集中的第一条记录以外?在运行时阅读您的想法,仅显示您最初想到的记录? TextBox通常显示多于一条记录的数据吗?

如果停止使用TextBoxes并使用能够进行更复杂的数据绑定的控件,则可能会得到想要的结果...

(此处有基础知识文章: .NET Windows窗体中的数据绑定概念 [
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[^])


我的朋友
我搜索参数,我只需要返回原始搜索结果即可返回
请帮我
my friend
i search for parameter and i need to return with only searched raw
plz help me


这篇关于用vb在sql上搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆