数据库和表绑定 [英] Database and Table Bindings
本文介绍了数据库和表绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,这实际上是我在这里的第一篇帖子,很高兴认识你们.
我是数据库创建的新手.我使用Visual Studio创建了一个数据库,该数据库中有两个表,我发现很难显示从两个表到一个datagridview的字段,请寻求有关如何解决此问题的帮助.提前谢谢.
美好的一天.
SUNNY OKORO
这是我为此编写的代码,
Hello friends, this is actually my first post here, good to have you people.
I am new to database creation. I created a database using visual studio, it has two tables in them, I am finding it difficult displaying fields from the two tables to one datagridview, please I need help on how to solve this problem. Thanks in advance.
Lovely day.
SUNNY OKORO
This is the code I wrote for it,
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB2TABS.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
conn.Open();
SqlCommand CMD = conn.CreateCommand();
CMD.CommandType = CommandType.Text;
//TABCOS, TABDETS ARE THE TABLE NAMES
CMD.CommandText = "SELECT TABCOS.REGNO. TABDETS.FIRSTNAME FROM TABCOS, TABDETS WHERE TABCOS.REGNO = TABDETS.REGNO";
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = CMD;
我不知道下一步该怎么做,请帮忙.谢谢.
I don''t know what to do next, Please help. Thanks.
推荐答案
试试看:-
"SELECT `TC.REGNO`, `TD.FIRSTNAME` FROM `TABCOS` TC INNER JOIN `TADDETS` TD ON `TC.REGNO` = `TD.REGNO`"
作为查询.
希望这有助于
Try this:-
"SELECT `TC.REGNO`, `TD.FIRSTNAME` FROM `TABCOS` TC INNER JOIN `TADDETS` TD ON `TC.REGNO` = `TD.REGNO`"
as your query.
Hope this helps
使用Join从两个表中获取数据,然后
use Join to get data from two tables then
SqlDataAdapter dt = new SqlDataAdapter(CommandObject)
//Declare DataSet and assign dataadapter value to dataset
using System.Data
DataSet ds = new dataSet ();
dt.fill(ds);
//to bind gridview Use
gridview1.DataSource = ds
gridview1.DataBind();
这篇关于数据库和表绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文