通过vb.net从sql检索数据 [英] retrive data from sql by vb.net

查看:89
本文介绍了通过vb.net从sql检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

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

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

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


Dear all,

I have created a small vb.net program.

I need to retrive 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 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


[edit]已从内联代码"转换为代码块" = OriginalGriff [/edit]


[edit]Converted from "inline code" to "code block" = OriginalGriff[/edit]

推荐答案

不清楚您想要的内容和编码.据我了解,这是一个简单的检索功能,在谷歌搜索中您会看到很多示例,复制并粘贴代码,更改sql语句并相应地进行其他更改.

这是我在谷歌上搜索的第一个链接[^] :
Not clear with what you want and the coding. As far as I understood this is a simple retrieve function, which on googling you get so many examples, Copy and paste the code, change the sql statement and do other changes accordingly.

Here is the first link[^]which I got on the googling :)


从此行中删除"WHERE"一词:
Remove one of the "WHERE" words from this line:
Private coomd As New SqlCommand("SELECT * from EM_TBL where Where EM_NAME =@ddd", sqlconn)


当它像这样出现时:


When it lloks like this:

Private coomd As New SqlCommand("SELECT * FROM EM_TBL WHERE EM_NAME =@ddd", sqlconn)

它会更好地工作...

It will work better...


我删除了哪里,但我不知道为什么通过db中的记录记录返回,这意味着它使用数据专家的值返回(从EM_TBL中选择* )
我需要搜索命令的值,而不是sql适配器的值
如果我错了,请修正给我
感谢您的回答
i remove where but i dont know why return by firt record in db that mean it return with the value from data adepter (select * from EM_TBL)
i need the value from search command not from the sql adapter
please fix to me if i am wrong
i appreciate your answer


这篇关于通过vb.net从sql检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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