所以我有一個從我的數據庫顯示記錄的問題。我的表單只有兩個數據網格。這裏是我的代碼:來自sql數據庫的記錄沒有顯示在數據網格上
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上的一個教程。我檢查了很多次,但我似乎無法弄清楚這些錯誤或連接參數。
預先感謝您!
視頻來源:https://www.youtube.com/watch?v=m_K__V0rIz4
缺少你的dgV.DataBind()和dgI.DataBind()? –
這個人沒有添加它:(加上我沒有添加到我以前的項目,當我顯示數據 – dsanatomy