本文介绍了Vb.net我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!
我想从名为cdirlocal的表中读取数据()。
并将所有单词插入listbox1(en),listbox2(type)和listbox3(pl),但列表框中没有显示任何内容。我需要做些什么来使它工作?
我尝试过的事情:
我有这个代码:
进口 System.Data
Imports System.Data.SqlClient
Public 类 Form1
Dim 表作为 字符串()
Dim 命令 As SqlCommand
Dim Reader As SqlDataReader
私有 Sub Form1_Load(发件人 As 对象,e As EventArgs)句柄 MyBase .Load
Dim conn As SqlConnection = 新 SqlConnection( 服务器SRV =;数据库=分贝;用户ID =用户名;密码=通过;)
尝试
conn.Open()
Dim 查询作为 字符串
查询= SELECT * FROM`cdirlocal`
Command = 新 SqlCommand(Query,conn)
Reader = Command.ExecuteReader
while Reader.Read
ListBox1.Items.Add(Reader.GetString( en))
ListBox2.Items .Add(Reader.GetString( pl))
ListBox3.Items.Add( Reader.GetString( type))
结束 while
conn.Close()
Catch ex As 异常
MsgBox( 发生错误:& ex.ToString)
结束 尝试
结束 Sub
私有 Sub Button3_Click(发件人作为 对象,e As EventArgs)句柄 Button3.Click
Application。退出()
结束 Sub
结束 类
解决方案
Hi!
I want to read data from table named cdirlocal (Screenshot).
and insert all words to listbox1 (en), listbox2 (type) and listbox3 (pl), but there is nothing showing in listboxes. What do I need to do to make it working???
What I have tried:
I have this code:
Imports System.Data Imports System.Data.SqlClient Public Class Form1 Dim table As String() Dim Command As SqlCommand Dim Reader As SqlDataReader Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim conn As SqlConnection = New SqlConnection("Server=srv; Database=db; UserId=username; Password=pass;") Try conn.Open() Dim Query As String Query = "SELECT * FROM `cdirlocal`" Command = New SqlCommand(Query, conn) Reader = Command.ExecuteReader While Reader.Read ListBox1.Items.Add(Reader.GetString("en")) ListBox2.Items.Add(Reader.GetString("pl")) ListBox3.Items.Add(Reader.GetString("type")) End While conn.Close() Catch ex As Exception MsgBox("An error has occured: " & ex.ToString) End Try End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Application.Exit() End Sub End Class
解决方案
这篇关于Vb.net我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!