C#第一次使用数据库 [英] c# first time working with database

查看:68
本文介绍了C#第一次使用数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

即时通讯首次在c#中使用数据库.
我想知道如何阅读,比较值
在不同的数据表中.

最重要的是,如何从数据表中获取一行的所有值.
我有4个数据表.在ech表中有一些行.现在我明白了
排成表格.通过这样做,我创建了与
表的关系 数据集.

之后,我打开了数据集.我已经看到可以通过右键单击"
添加一种从表querry中搜索/输出值的方法.

现在,我通过单击表格并设置方法设置来启动Querry帮助器,
寻找我的价值.之后,我打开表格并设置表格和
表适配器.我用"foreach"搜索该表.一切正常.

但是,现在我需要搜索另一个表,并通过相同的过程进行操作
如所解释的那样,它不起作用,它告诉我创建查询时,
shema是另一个主要查询.

如果您需要更精确的说明,请告诉我.

谢谢

问候Niko

hi guys,

im for first time using a database in c#.
I would like to know how do i read, compare values
in different data tables.

And most important, how do i get all values of a row from a datatable.
I have 4 DataTables. In ech table are some rows. Now i get that
rows into a form. By doing this, i have created relations to the tables from
the dataset.

After that, i opened the dataset. I have seen that it is possible on "right-click"
to add a method for searching/output values from tables, querry.

Now i started the querry helper, by clicking my table and set the method settings,
for searching my value. Afterwards i opened my form and set the Table and the
table adapter. I searched that table with "foreach". Everything works fine.

But, now i need to search another table, and by doing this by the same proces
as explained it doesnt work, it tells me on creating the query, the
shema is another as the main query.

Let me know if you need a more precise explaination.

Thank you

Greets Niko

推荐答案

using System.Data;
using System.Data.SqlClient;

SqlConnection con=new SqlConnection("Connection string of your database");

string query="select * from users";
SqlDataAdapter da=new SqlDataAdapter(query, con);
DataTable dt=new DataaTable();
da.fill(dt);

foreach(DataRow dr in dt.Rows)
{
   if(dr["FirstName"].ToString()== fnameTxtBox.Text)
       Label.Text = "Welcome "+fnameTxtBox.Text;
}   // you can loop through all the records (i.e Rows) using this loop, modify the code as per requirements


这篇关于C#第一次使用数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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