代码以从sql server中的表填充数据网格中的数据 [英] code to populate data in data grid from table in sql server

查看:55
本文介绍了代码以从sql server中的表填充数据网格中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我应该获得在网格中填充表数据的代码.以后我也应该可以编辑和保存.我正在使用以下代码从表中获取数据,但是它不起作用

Hello Everyone

I should get the code to populate table data in grid. later i should also be in position to edit and save. the following code i am using to get data from the table but it is not working

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myconnection As New SqlConnection("server=THEJASVI-PC\SQLEXPRESS;database=emp;uid=sa;pwd=2x12")
        myconnection.Open()
        ds = New DataSet()
        s = "select * from emp_details"

        Dim da As New SqlDataAdapter(s, myconnection)

        da.Fill(ds, "emp_details")
        dgvEmployeedetails.DataSource = ds.DefaultViewManager


    End Sub



因此,请帮助我更正我的代码



so help me kindly to correct my code

推荐答案

您错过了将SQL Command与适配器相关联的操作.

看一下如何使用DataAdapter填充数据集:
SqlDataAdapter类 [
You missed to associate SQL Command to the adapter.

Have a look here of how to use DataAdapter to fill dataset:
SqlDataAdapter Class[^]


dgvEmployeedetails.DataSource = ds.DefaultViewManager



我将其更改为




I would change this to


dgvEmployeedetails.DataSource = ds.tables(0)



您显示的示例可以使用,但是sandeep发布的链接是使用更好的解决方案,更易于维护



The example you''ve shown will work, but the link that sandeep has posted is the better solution to use, more maintainable


这篇关于代码以从sql server中的表填充数据网格中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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