当前位置:编程学习 > C#/ASP.NET >>

各位老师 请看一下这代码哪一点出错了。 我是菜鸟 呵呵

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnetion con = new SqlConection("Data Source=LZY_PC;Tnitial Catalog=学生管理系统;Integrated Security=True");
            string sqlStr = string.Format("select count(*)lzy where  UserTable='{0}'andPassword='{1}'.txtUserName.Text,txtPassword.Text");
            SqlCommand com = new SqlCommand(sqlStr, con);
            con.Open();
            int result = (int)com.ExecuteScalar();
            con.Close();
            if (result == 1)
            {
                Form2 fm = new Form2();
                fm.Show();
            }
            else
            {
                MessageBox.Show("用户名或者密码错误!请重新输入!"); 
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }
    }
}
--------------------编程问答-------------------- Tnitial Catalog

请写成Intial Catalog --------------------编程问答-------------------- sql语句那块有问题,好好检查检查 --------------------编程问答--------------------
 select count(*)lzy where UserTable='{0}'andPassword='{1}'
 靠的太近了

应该写成
 select count(*) lzy  where UserTable='{0}'and  Password='{1}'
--------------------编程问答-------------------- 另外,记得贴错误出来,不然不好找问题 --------------------编程问答-------------------- 你说出错了, 好歹也把错误提示贴出来吧。 --------------------编程问答--------------------   select count(*) lzy  where UserTable='{0}' and  Password='{1}'
  --------------------编程问答--------------------   SqlConnetion con = new SqlConection("Data Source=LZY_PC;Initial Catalog=学生管理系统;Integrated Security=True"); --------------------编程问答-------------------- SqlConnetion con = new SqlConection("Data Source=LZY_PC;Initial Catalog=学生管理系统;Integrated Security=True");

select count(*) lzy  where UserTable='{0}'and  Password='{1}'

不用给我分,上面已经回答了 --------------------编程问答-------------------- use break point to find out the error and then easy to find out. --------------------编程问答-------------------- 错误 1 找不到类型或命名空间名称“SqlConnetion”(是否缺少 using 指令或程序集引用?) f:\c#\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 27 13 WindowsFormsApplication1


这是错误  各位老师的回答我刚才看了。确实有代码输入错了、但是好像主要不是这个问题。  --------------------编程问答--------------------
引用 10 楼 lzy_0230916 的回复:
错误 1 找不到类型或命名空间名称“SqlConnetion”(是否缺少 using 指令或程序集引用?) f:\c#\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 27 13 WindowsFormsApplication1


这是错误 各位老师的回答我刚才看了。确实有代码输入错了、但是好像主要不是这个问题。

你应该早点贴错误上来,
你没有引用命名空间:
加上:
using System.Data;
using System.Data.SqlClient; --------------------编程问答--------------------  string sqlStr = string.Format("select count(*)lzy where UserTable='{0}'andPassword='{1}'.txtUserName.Text,txtPassword.Text");
sql语句这里写错了
应该是
string.Format("select count(*)lzy where UserTable='{0}'andPassword='{1}'",txtUserName.Text,txtPassword.Text);
--------------------编程问答--------------------
引用 12 楼 wsd_asp 的回复:
string sqlStr = string.Format("select count(*)lzy where UserTable='{0}'andPassword='{1}'.txtUserName.Text,txtPassword.Text");
sql语句这里写错了
应该是
string.Format("select count(*)lzy where UserTable='{0}'a……

string.Format("select count(*)lzy where UserTable='{0}'and Password='{1}'",txtUserName.Text,txtPassword.Text); --------------------编程问答-------------------- SqlConnetion con = new SqlConection("Data Source=LZY_PC;Initial Catalog=学生管理系统;Integrated Security=True");  这应该还差一个链接到数据库的用户名或密码吧! --------------------编程问答-------------------- 参考 --------------------编程问答-------------------- string sqlStr = string.Format("select count(*)lzy where UserTable='{0}'andPassword='{1}'.txtUserName.Text,txtPassword.Text");
 你这个sql语句我觉得也不对  怎么没有‘from’  我觉得也会出错 --------------------编程问答-------------------- --------------------编程问答-------------------- select count(*) as lzy  where UserTable='{0}'and  Password='{1}'
--------------------编程问答-------------------- 。。。。好多错,建议找个懂的人当面指导
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,