已有56人关注
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项
贴补了图  不好意思
分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2009-07-06
沙发
读者朋友:
    您好,你打开tb_avin1这个表,看一下里面是不是只有一条记录。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照