C#看到SQL时照书上打代码出错……
                 	
                        发表在C#图书答疑
                        2009-07-06                                                
                    		
                                                                            	
                        
                        
                    
                    
                    	是否精华
                    	是
                    	否
                    
                    
                    
                            版块置顶:
                            是
                            否
                        
                    
                                           using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 第十五章_Command对象
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection A;
private void button1_Click(object sender, EventArgs e)
{
try
{
if (A.State == ConnectionState.Open || textBox1.Text != "")
{
SqlCommand B = new SqlCommand();
B.Connection = A;
B.CommandText = "select count(*)from" + textBox1.Text.Trim();
B.CommandType = CommandType.Text;
int C = Convert.ToInt32(B.ExecuteScalar());
label1.Text = "数据表中共有:" + C.ToString() + "条数据";
}
}
catch(Exception D)
{
label1.Text = D.Message;
}
}
private void Form1_Load(object sender, EventArgs e)
{
A = new SqlConnection("server=.;database=db_foavin;uid=sa;pwd=");
A.Open();
}
}
}
为什么书上查有7条 我再怎么查也只有1条……
麻烦帮忙 谢谢!
我查询的是db_foavin下的tb_avin1表
里面建了5项
贴补了图 不好意思
                
        	
        
        
    using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 第十五章_Command对象
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection A;
private void button1_Click(object sender, EventArgs e)
{
try
{
if (A.State == ConnectionState.Open || textBox1.Text != "")
{
SqlCommand B = new SqlCommand();
B.Connection = A;
B.CommandText = "select count(*)from" + textBox1.Text.Trim();
B.CommandType = CommandType.Text;
int C = Convert.ToInt32(B.ExecuteScalar());
label1.Text = "数据表中共有:" + C.ToString() + "条数据";
}
}
catch(Exception D)
{
label1.Text = D.Message;
}
}
private void Form1_Load(object sender, EventArgs e)
{
A = new SqlConnection("server=.;database=db_foavin;uid=sa;pwd=");
A.Open();
}
}
}
为什么书上查有7条 我再怎么查也只有1条……
麻烦帮忙 谢谢!
我查询的是db_foavin下的tb_avin1表
里面建了5项
贴补了图 不好意思

 
	
                                                 VIP会员
VIP会员 购物车
购物车

 私信
                         私信 
                     发表新帖
发表新帖 立即签到
立即签到 
        		  
        		 
         		 关注
关注
                  回复
 回复 支持(
                	支持( 反对(
                    反对( 
                







 
                     
                     
					 
						 
						 
						 
						