DataGridView不显示数据 [英] DataGridView Does Not Showing Data

查看:68
本文介绍了DataGridView不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有错误,警告和消息。

但是datagridview没有显示我想要显示的数据。

请帮助,这是我的源代码连接



there are no error, warning and message.
but the datagridview does not showing data that i want to show.
please help, this is my source code for connection

<br />
Imports System.Data.Odbc<br />
Imports System.Data<br />
<br />
Module koneksi<br />
    Public conn As OdbcConnection<br />
    Public da As OdbcDataAdapter<br />
    Public ds As DataSet<br />
    Public strcon As String<br />
<br />
    Public Sub konek()<br />
        strcon = "Driver=(MySQL ODBC 5.3.4 Driver};database=simrencana;port=3306;server=localhost;uid=root"<br />
        conn = New OdbcConnection(strcon)<br />
        If conn.State = ConnectionState.Closed Then<br />
            conn.Open()<br />
        End If<br />
<br />
    End Sub<br />
End Module<br />
<br />





,这是m主要源代码



and this is my main source code

<br />
Imports System.Data.Odbc<br />
Imports System.Data<br />
<br />
Public Class Form1<br />
<br />
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
        konek()<br />
        da = New Odbc.OdbcDataAdapter("select * from jadwal", conn)<br />
        ds = New DataSet<br />
        conn.Close()<br />
        'ds.Clear()<br />
        da.Fill(ds.Tables("jadwal"))<br />
        dg.DataSource = (ds.Tables("jadwal"))<br />
<br />
<br />
    End Sub<br />

推荐答案

在调用填充操作之前无需关闭连接。 dataadapter具有内置功能,可在填充完成后自动关闭连接。



或填写后可以关闭连接()。



There is no need to close the connection before calling the fill operation. dataadapter has inbuilt feature to close the connection automatically as soon as fill completes.

or you can close the conection after fill().

OdbcConnection conn;
OdbcDataAdapter ap;
DataSet ds = new DataSet();
string constr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=TEST;UID=root;PW D=pass;OPTION=3";conn = new OdbcConnection(constr);
conn.Open();
ap = new OdbcDataAdapter(cmdstr,conn);
ap.Fill(ds,"MyTable");
this.dgMy.DataSource = ds;
this.dgMy.DataMember = "MyTable";


我终于知道我的代码有什么问题了。

这个字符串'Driver =(MySQL ODBC 5.3) .4 Driver}'不应该写在连接字符串中。

当我尝试这个连接字符串时没有'Driver =(MySQL ODBC 5.3.4 Driver}'它可以工作。



strcon =Server = localhost; User Id = root; Password =; Database = simrencana



非常感谢satendra的帮助:)
i finally know what wrong in my code.
this string 'Driver=(MySQL ODBC 5.3.4 Driver}' shouldn't be write in the connection string.
when i tried this connection string without 'Driver=(MySQL ODBC 5.3.4 Driver}' it works.

strcon = "Server=localhost;User Id=root;Password=;Database=simrencana"

thank you so much satendra for your help :)


这篇关于DataGridView不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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