首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

课程设计又碰到麻烦了,请各位老师给指点下,不胜感激!

2013-12-02 
课程设计又遇到麻烦了,请各位老师给指点下,不胜感激!!!using Systemusing System.Collections.Genericus

课程设计又遇到麻烦了,请各位老师给指点下,不胜感激!!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 登录设计
{
    public partial class student : Form
    {
        public student()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string cstr = @"Data Source=.;Initial Catalog=login;Integrated Security=True";
            string sql1 = string.Format("select *from login where Name='{0}'",textBox1.Text.Trim());
            string sql=string.Format("update login set Pwd='{0}' where Name={1}",textBox4.Text,textBox1.Text);
            using (SqlConnection conn = new SqlConnection(cstr))
            {
                using (SqlCommand cmd = new SqlCommand(sql1,conn))
                {
                    conn.Open();
                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        if (rd.Read())
                        {
                            if (rd.GetString(2) == textBox3.Text.Trim())
                                if (textBox4.Text == textBox5.Text)
                                {
                                    rd.Close();
                                    using (SqlCommand cad = new SqlCommand(sql, conn))
                                    {
                                        cad.ExecuteNonQuery();
                                    }
                                    MessageBox.Show("修改密码成功!");
                                    foreach (Control ctrl in Controls)
                                    {
                                        if (ctrl is TextBox)


                                            ctrl.Text = "";//登录成功时清除文本框中的数据
                                    }
                                }
                                else
                                    MessageBox.Show("两次输入的密码不一致!!!");
                            else
                                MessageBox.Show("原始密码错误,请正确输入!!!");
                        }
                        else
                            MessageBox.Show("请输入正确的用户名!!!");
                    }
                }
            }
        }
    }
}
这是其中的一个界面,有个功能是修改密码,但是修改的时候老是报错,能请大家给指点下! c# 数据库
[解决办法]
手机看不清图片,明天再看看吧
[解决办法]
string sql1 = string.Format("select *from login where Name='{0}'",textBox1.Text.Trim());
这个有问题,星号后面加上空格。
[解决办法]


string sql=string.Format("update login set Pwd='{0}' where Name={1}",textBox4.Text,textBox1.Text);

少了一组单引号
where Name '{1}'
[解决办法]
update login set Pwd='{0}' where Name={1}",textBox4.Text,textBox1.Text);
Name = '{1}'
z这样改
[解决办法]
CSDN 现在成了学生的天堂了!

热点排行