【发布时间】:2014-03-28 20:16:05
【问题描述】:
所以我在显示我的数据库中的记录时遇到了问题。我的表单只有两个数据网格。这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace testare_selectie
{
public partial class Form1 : Form
{
DataSet ds = new DataSet();
SqlDataAdapter daVendors = new SqlDataAdapter();
SqlDataAdapter daInvoices = new SqlDataAdapter();
SqlConnection cs = new SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=db;integrated security = TRUE");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlCommand slctVendors = new SqlCommand("SELECT * FROM Developerss ",cs);
daVendors.SelectCommand = slctVendors;
daVendors.Fill(ds,"Developerss");
SqlCommand slctInvoices = new SqlCommand("SELECT * FROM Games", cs);
daVendors.SelectCommand = slctInvoices;
daVendors.Fill(ds, "Games");
dgV.DataSource = ds.Tables["Developerss"];
dgI.DataSource = ds.Tables["Games"];
}
}
}
另外我想提一下,在此之前我之前做过一个项目,它也有一个显示按钮并且它有效,我不确定为什么这个不是。我跟进了来自 youtube 的教程。我检查了很多次拼写错误或连接参数,我似乎无法弄清楚这一点。
提前谢谢你!
【问题讨论】:
-
缺少您的 dgV.DataBind() 和 dgI.DataBind()?
-
那家伙没有添加它 :( 。另外,当我显示数据时,我没有将它添加到我以前的项目中