如何在C#中添加数据集中的多个表 [英] How to add multiple tables in dataset in C#
本文介绍了如何在C#中添加数据集中的多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void AcNotextBox_TextChanged(object sender, EventArgs e)
{
int id;
if (!int.TryParse(AcNotextBox.Text, out id))
{
return;
}
string connString = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString;
string cmdString = "SELECT * FROM tblBasicInfo WHERE ID =" +Convert.ToString(AcNotextBox.Text);
string cmdStringg = "SELECT * FROM tblAccData WHERE ID =" + Convert.ToString(AcNotextBox.Text);
using (OleDbConnection conn = new OleDbConnection(connString))
{
using (OleDbCommand cmd = new OleDbCommand(cmdString, conn))
{
cmd.Parameters.AddWithValue("ID", id);
conn.Open();
OleDbDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
NametextBox.Text = (reader["SName"].ToString());
FNametextBox.Text = (reader["FName"].ToString());
AddresstextBox.Text = (reader["Address"].ToString());
CelltextBox.Text = (reader["Cell"].ToString());
NationalitytextBox.Text = (reader["Nationality"].ToString());
ReligiontextBox.Text = (reader["Religion"].ToString());
FCNICNotextBox.Text = (reader["FCNICNo"].ToString());
FatherOccuptextBox.Text = (reader["FOccup"].ToString());
TransportFacilitytextBox.Text = (reader["TranFacility"].ToString());
InFiguredateTimePicker.Text = (reader["DOB"].ToString());
DateofAdmdateTimePicker.Text = (reader["DateofAdm"].ToString());
RegistrationNotextBox.Text = (reader["RegNo"].ToString());
TranFeetextBox.Text = (reader["TransportChr"].ToString());
SRemarkstextBox.Text = (reader["SpecialRemarks"].ToString());
ClassofcomboBox.Text = (reader["ClassofAdm"].ToString());
ClassOfReadcomboBox.Text = (reader["ClassofReading"].ToString());
}
}
我的尝试:
如何添加多表数据ne window fox 9文本框我要设置或填写,显示c#中的数据请帮助我
What I have tried:
how to add multi table data ne window fox 9 text box i want to set or fill, dispaly data in c# Please Help me
推荐答案
在此处查看答案: c# - 使用多个表选择查询加载DataTable - 堆栈溢出 [ ^ ]
您可以在Access中使用 INNER JOIN ,如下所示,请参阅内部联接操作(Microsoft Access SQL) [ ^ ]
See answers here: c# - Loading DataTable with multiple tables select query - Stack Overflow[^]
You can use INNER JOIN in Access as follows, see INNER JOIN Operation (Microsoft Access SQL)[^]
SELECT CategoryName, ProductName
FROM Categories INNER JOIN Products
ON Categories.CategoryID = Products.CategoryID;
以下是如何从Access加载 DataTable 的示例,已复制来自在C#中使用Microsoft Access数据库。 。 。在Winforms / WPF初学者中的ADO.NET [ ^ ]
Here is an example how to load a DataTable from Access, copied from Using Microsoft Access Database In C# . . . ADO.NET In Winforms/WPF For Beginners[^]
var conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=Store.mdb;");
conn.Open();
var dtCustomers = new DataTable();
var adapter = new OleDbDataAdapter("SELECT * FROM Customers;",
conn);
adapter.Fill(dtCustomers);
dataGridView1.DataSource = dtCustomers;
这篇关于如何在C#中添加数据集中的多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文