本文介绍了sql数据库读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何将sql server数据库中特定列的entir数据选择为像lables这样的表单组件?我的代码看起来像这样---这里我没有为lable2设定价值。 private void timer1_Tick( object sender,EventArgs e) { try { SqlConnection con = new SqlConnection( @ Server = 192.168.1.4; Database = DIGIQUEUE; User Id = digiq; Password = digiq123;); con.Open(); string sql1 = 从callpad中选择callpad_status ; SqlCommand cmd = new SqlCommand(sql1,con); SqlDataReader sqlReader = cmd.ExecuteReader(); while (sqlReader.Read()) { label1.Text = sqlReader.GetValue( 0 )的ToString(); label2.Text = sqlReader.GetValue( 1 )。ToString(); } sqlReader.Close(); } catch (System.Exception ex) {} } 解决方案 我建​​议你从这里开始: ASP.NET概述 [ ^ ]并阅读所有相关文章。 接下来,看看示例: 初学者访问SQL指南服务器通过C# [ ^ ] 一个初学者的教程 - 了解ASP.NET中的ControlState [ ^ ] 初学者关于ASP.NET中母版页的教程 [ ^ ] 初学者的ASP.NET Web部件教程 [ ^ ] 了解ASP.NET应用程序和页面生命周期 - 初学者的教程 [ ^ ] 了解ASP.NET角色和会员资格 - 初学者教程 [ ^ ] ASP.NET代码示例下载 [ ^ ] 来自MSDN和ASP.NET的ASP.NET代码示例 [ ^ ] 我认为它''足够开始...... 检查这个 私人 无效 timer1_Tick( object sender,EventArgs e) { try { SqlConnection con = new SqlConnection( @ Server = 192.168.1.4; Database = DIGIQUEUE; User Id = digiq; Password = digiq123;); con.Open(); string sql1 = 从callpad中选择callpad_status ; SqlCommand cmd = new SqlCommand(sql1,con); SqlDataReader sqlReader = cmd.ExecuteReader(); label1.Text = ; while (sqlReader.Read()) { label1.Text = label1.Text + sqlReader.GetValue( 0 )的ToString(); // 您只在选择查询中选择一列。当您在查询中再添加一列时,您可以使用与label1相同的label2 label2.Text = sqlReader.GetValue( 1 )。ToString(); } sqlReader.Close(); } catch (System.Exception ex) {} } 您好, 请更改这样的选择查询.. 从 tablename中选择 columnname1,columnname2 然后你可以得到lable2的值 how to select entir data of a specific column in sql server database into a form components like lables? my code look like this---here i am not geting the value for lable2.private void timer1_Tick(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(@"Server=192.168.1.4;Database=DIGIQUEUE;User Id=digiq;Password=digiq123;"); con.Open(); string sql1 = "Select callpad_status from callpad "; SqlCommand cmd = new SqlCommand(sql1, con); SqlDataReader sqlReader = cmd.ExecuteReader(); while (sqlReader.Read()) { label1.Text = sqlReader.GetValue(0).ToString(); label2.Text = sqlReader.GetValue(1).ToString(); } sqlReader.Close(); } catch (System.Exception ex) { } } 解决方案 I would suggest you to start here: ASP.NET Overview[^] and read all related articles.Next, have a look at examples:Beginners guide to accessing SQL Server through C#[^]A Beginner''s Tutorial - Understanding ControlState in ASP.NET[^]Beginner''s Tutorial on Master Pages in ASP.NET[^]A Beginner''s Tutorial on ASP.NET Web Parts[^]Understanding ASP.NET Application and Page Life Cycle - A Beginner''s Tutorial[^]Understanding ASP.NET Roles and Membership - A Beginner''s Tutorial[^]ASP.NET Code Sample Downloads[^]ASP.NET Code Examples from MSDN and the ASP.NET[^]I think it''s enough for start...check thisprivate void timer1_Tick(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(@"Server=192.168.1.4;Database=DIGIQUEUE;User Id=digiq;Password=digiq123;"); con.Open(); string sql1 = "Select callpad_status from callpad "; SqlCommand cmd = new SqlCommand(sql1, con); SqlDataReader sqlReader = cmd.ExecuteReader(); label1.Text=""; while (sqlReader.Read()) { label1.Text =label1.Text + sqlReader.GetValue(0).ToString(); //you are selecting only one column in your select query. when you will add one more column in your query then you can use label2 same as label1 label2.Text = sqlReader.GetValue(1).ToString(); } sqlReader.Close(); } catch (System.Exception ex) { } }Hi,Please change the select query like this ..Select columnname1 , columnname2 from tablenamethen you can get the value of lable2 这篇关于sql数据库读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS!
05-23 06:04