本文介绍了如何从多个sql表中读取(只知道列名而不是表名)c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 所以我在这里再问一个问题!好的,我的问题是如果我只知道列名,我如何从多个sql表中读取数据。 EG。 eqcas数据库 [用户信息] - cas_user_ext - eqcas 电子邮件地址 - 电子邮件 全名 - 全名 [用户PIN码] - cat_validation - eqcas 名称 - 名称 主要针脚 - 主要针脚 辅助针 - 次要针 cas_user_ext(表格) cat_validation(表格) text(列名) public EQData() { SQLConnect sqlcon = new SQLConnect(); SqlDataReader myReader = null ; // SqlCommand myCommand = new SqlCommand(select x_id,fullname,email FROM cas_user_ext WHERE fullname = @fullname , // sqlcon.Connection); SqlCommand myCommand = new SqlCommand( select x_id,fullname,email ,name,primarypin,secondarypin FROM cas_user_ext,cat_validation WHERE name = @name, sqlcon.Connection); myCommand.Parameters.AddWithValue( @ name, ivan1); myReader = myCommand.ExecuteReader(); while (myReader.Read()) { x_id = myReader [ x_id]。ToString(); fullname = myReader [ fullname]。ToString(); email = myReader [ email]。ToString(); name = myReader [ name]。ToString(); primarypin = myReader [ primarypin]。ToString(); secondarypin = myReader [ secondarypin]。ToString(); } sqlcon.Close(); } } 我也正在使用课程来获取信息(以上是我班级的一部分) 所以我想说要从中检索数据所有列的两个表,但我唯一的信息是用户名称。我将如何实现这一目标? 当我运行我的应用程序时,我正在检索cas_user_ext表的正确信息,但不检索cat_validation,cat_validation检索不同的用户信息。 /> 提前谢谢解决方案 你需要用cas_user_ext xid加入cat_validation id。 试试这个sql: 选择ue.x_id,ue。 full_cn,ue.email,ct.name,ct.primarypin,ct.secondarypin from cat_validation as ct join cas_user_ext as ue on ct.id = ue.x_id where ct.name = @name Hi all,So here i am asking a question once again! Okay so my question is how do i read data from multiple sql tables if i only know the column names. EG.eqcas database[User Info] - cas_user_ext - eqcasEmail adress - "email"Full Name - "fullname"[User Pin] - cat_validation - eqcasName - "name"Primary Pin - "primarypin"Secondary Pin - "secondarypin"cas_user_ext (table)cat_validation (table)"text" (the column names) public EQData() { SQLConnect sqlcon = new SQLConnect(); SqlDataReader myReader = null; //SqlCommand myCommand = new SqlCommand("select x_id, fullname, email FROM cas_user_ext WHERE fullname = @fullname", //sqlcon.Connection); SqlCommand myCommand = new SqlCommand("select x_id, fullname, email, name, primarypin, secondarypin FROM cas_user_ext, cat_validation WHERE name = @name", sqlcon.Connection); myCommand.Parameters.AddWithValue("@name", "ivan1"); myReader = myCommand.ExecuteReader(); while (myReader.Read()) { x_id = myReader["x_id"].ToString(); fullname = myReader["fullname"].ToString(); email = myReader["email"].ToString(); name = myReader["name"].ToString(); primarypin = myReader["primarypin"].ToString(); secondarypin = myReader["secondarypin"].ToString(); } sqlcon.Close(); }}and also i'm using a class to get the info (the above is part of my class)So lets say i want to retrieve data from from both tables for all the columns, but the only info i have is the users "name". How would i achieve that?When i run my application i am retrieving the correct information for cas_user_ext table but not for cat_validation, cat_validation retrieve a different users information.Thanks in advance 解决方案 这篇关于如何从多个sql表中读取(只知道列名而不是表名)c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 12:05