| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 718 人关注过本帖
标题:请教一个关于用dataset搜索数据问题
只看楼主 加入收藏
kidangel666
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:139
注 册:2010-9-15
结帖率:78.95%
收藏
已结贴  问题点数:20 回复次数:5 
请教一个关于用dataset搜索数据问题
我在一个工程里面创建了3个窗口,他们都使用同一个dataset
但是我使用
 DataRow[] drSelect = this.权限管理DataSet.权限管理.Select("用户账号=" + "01");
时在form3的窗口中搜索不到数据,在其他2个窗口中找得到,
我说明  我form2是form1的子窗口,form1是form3的子窗口
WindowsApplication1.rar (150.45 KB)
搜索更多相关主题的帖子: 搜索 工程 用户 账号 
2012-01-08 15:17
kidangel666
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:139
注 册:2010-9-15
收藏
得分:0 
为了方便  我在form1的 保存按钮的点击事件里面添加DataRow[] drSelect = this.权限管理DataSet.权限管理.Select("用户账号=" + "01");
同时在form3的 登录按钮里面添加
2012-01-08 15:25
kidangel666
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:139
注 册:2010-9-15
收藏
得分:0 
程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
    public partial class authorityForm : Form
    {
        private string use_Account = string.Empty;
        private string use_Password = string.Empty;
        private string use_name = string.Empty;
        private bool lesson_Query;
        private bool lesson_Add;
        private bool lesson_Del;
        private bool score_Query;
        private bool score_Add;
        private bool score_Del;
        private bool score_Edit;
        private string use_Message = string.Empty;
        private bool save_Sign = false;
     
        public authorityForm()
        {
            InitializeComponent();
        }
        private void authorityForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the '权限管理DataSet.权限管理' table. You can move, or remove it, as needed.
            this.权限管理TableAdapter.Fill(this.权限管理DataSet.权限管理);
        }
        private void update_DataSet()
        {
            this.权限管理TableAdapter.UpdateQuery(
                     use_name,
                     lesson_Query,
                     lesson_Add,
                     lesson_Del,
                     score_Query,
                     score_Add,
                     score_Del,
                     score_Edit,
                     use_Message,
                     use_Account);
            save_Sign = false;
        }
      
        private void saveBtn_Click(object sender, EventArgs e)
        {
            update_DataSet();
            DialogResult result = MessageBox.Show("是否保存?", "保存提示", MessageBoxButtons.OK);
            if (result == DialogResult.OK)
            {
                DataRow[] drSelect = this.权限管理DataSet.权限管理.Select("用户账号=" + "01");               这里时form1,搜索得到
                DataRow editDr = drSelect[0];
                this.权限管理TableAdapter.Update(this.权限管理DataSet.权限管理);
                save_Sign = true;
                this.权限管理TableAdapter.Fill(this.权限管理DataSet.权限管理);
             
            }
          
           

        }
        private void closeBtn_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("是否退出?", "退出提示", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {
                if (save_Sign == false)
                {
                    this.权限管理BindingSource.CancelEdit();
                }
                this.Close();
            }
            else
            {
                this.权限管理TableAdapter.Fill(this.权限管理DataSet.权限管理);
            }
          
        }
        private void delBtn_Click(object sender, EventArgs e)
        {
            this.权限管理BindingSource.RemoveCurrent();
        }
        private void accountTextBox_TextChanged(object sender, EventArgs e)
        {
            use_Account = accountTextBox.Text.ToString();
        }
        private void passwordTextBox_TextChanged(object sender, EventArgs e)
        {
            use_Password = passwordTextBox.Text.ToString();
        }
        private void nameTextBox_TextChanged(object sender, EventArgs e)
        {
            use_name = nameTextBox.Text.ToString();
        }
        private void messageTextBox_TextChanged(object sender, EventArgs e)
        {
            use_Message = messageTextBox.Text.ToString();
        }
        private void lessonQueryCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            lesson_Query = lessonQueryCheckBox.Checked;
            lessonCheckBox_State();
        }
        private void lessonAddCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            lesson_Add = lessonAddCheckBox.Checked;
            lessonCheckBox_State();
        }
        private void lessonDelCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            lesson_Del = lessonDelCheckBox.Checked;
            lessonCheckBox_State();
        }
        private void scoreQueryCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            score_Query = scoreQueryCheckBox.Checked;
            scoreCheckBox_State();
        }
        private void scoreAddCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            score_Add = scoreAddCheckBox.Checked;
            scoreCheckBox_State();
        }
        private void scoreDelCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            score_Del = scoreDelCheckBox.Checked;
            scoreCheckBox_State();
        }
        private void scoreEditCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            score_Edit = scoreEditCheckBox.Checked;
            scoreCheckBox_State();
        }
        private void lessonCheckBox_State()
        {
            if (lesson_Query == lesson_Add)
            {
                if (lesson_Add == lesson_Del)
                {
                    if (lesson_Query)
                    {
                        lessonCheckBox.CheckState = CheckState.Checked;
                    }
                    else
                    {
                        lessonCheckBox.CheckState = CheckState.Unchecked;
                    }
                }
                else
                {
                    lessonCheckBox.CheckState = CheckState.Indeterminate;
                }
            }
            else
            {
                lessonCheckBox.CheckState = CheckState.Indeterminate;
            }
        }
        private void lessonCheckBox_CheckedChanged(object sender, EventArgs e)
        {
           

            if (lessonCheckBox.CheckState == CheckState.Checked)
            {
                lessonQueryCheckBox.Checked = true;
                lessonAddCheckBox.Checked = true;
                lessonDelCheckBox.Checked = true;
            }
            else if (lessonCheckBox.CheckState == CheckState.Unchecked)
            {
                lessonQueryCheckBox.Checked = false;
                lessonAddCheckBox.Checked = false;
                lessonDelCheckBox.Checked = false;
            }
            //lessonCheckBox_State();
            //MessageBox.Show(lessonQueryCheckBox.Checked.ToString() + lessonAddCheckBox.Checked.ToString() + lessonDelCheckBox.Checked.ToString());
        }
        private void scoreCheckBox_State()
        {
            if (score_Query == score_Add)
            {
                if (score_Add ==  score_Del)
                {
                     if( score_Del==score_Edit)
                     {
                         if (score_Query)
                         {
                             scoreCheckBox.CheckState = CheckState.Checked;
                         }
                         else
                         {
                             scoreCheckBox.CheckState = CheckState.Unchecked;
                         }
                      }
                      else
                      {
                          scoreCheckBox.CheckState = CheckState.Indeterminate;
                      }
                }
                else
                {
                    scoreCheckBox.CheckState = CheckState.Indeterminate;
                }
            }
            else
            {
                scoreCheckBox.CheckState = CheckState.Indeterminate;
            }
        }
        private void scoreCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (scoreCheckBox.CheckState == CheckState.Checked)
            {
                scoreQueryCheckBox.Checked = true;
                scoreAddCheckBox.Checked = true;
                scoreDelCheckBox.Checked = true;
                scoreEditCheckBox.Checked = true;
            }
            else if (scoreCheckBox.CheckState == CheckState.Unchecked)
            {
                scoreQueryCheckBox.Checked = false;
                scoreAddCheckBox.Checked = false;
                scoreDelCheckBox.Checked = false;
                scoreEditCheckBox.Checked = false;
            }
        }
      

        private void useListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            update_DataSet();
        }
        private void passwordEditBtn_Click(object sender, EventArgs e)
        {
            PasswordForm passwordFrom = new PasswordForm(use_Account);
         
            passwordFrom.Tag = this; 
            this.Hide();
            passwordFrom.Show();
        }
        private void AddBtn_Click(object sender, EventArgs e)
        {
        }
    
    }
}









2012-01-08 15:34
kidangel666
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:139
注 册:2010-9-15
收藏
得分:0 
程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class loginForm : Form
    {
        private string account = string.Empty;
        private string password = string.Empty;
      

        public loginForm()
        {
            InitializeComponent();
        }

        private void loginForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the '权限管理DataSet.权限管理' table. You can move, or remove it, as needed.
            this.权限管理TableAdapter.Fill(this.权限管理DataSet.权限管理);
        }
        private void accountTextBox_TextChanged(object sender, EventArgs e)
        {
            account = accountTextBox.Text.ToString();
        }
        private void passwTextBox_TextChanged(object sender, EventArgs e)
        {
            password = passwTextBox.Text.ToString();
        }
        private void loginBtn_Click(object sender, EventArgs e)
        {
            if (account != string.Empty)
            {
                DataRow[] drSelect = this.权限管理DataSet.权限管理.Select("用户账号=" + "01");   这里搜索不到
                //DataRow editDr = drSelect[0];
                if (drSelect.Length > 0)
                {
                    DataRow editDr = drSelect[0];
                  
                    if (password.Equals(editDr["密码"].ToString()))
                    {
                        if (password.Equals("00"))
                        {
                            authorityForm authorityForm = new authorityForm();
                            this.Close();
                            authorityForm.Show();
                        }
                        else
                        { }
                    }
                    else
                    {
                        MessageBox.Show("密码错误,请重新输入!", "提示", MessageBoxButtons.OK);
                        passwTextBox.SelectAll();
                        passwTextBox.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("用户不存在,请重新输入!", "提示", MessageBoxButtons.OK);
                    accountTextBox.SelectAll();
                    accountTextBox.Focus();
                }
            }
            else
            {
                MessageBox.Show("请输入用户名!", "提示", MessageBoxButtons.OK);
                accountTextBox.SelectAll();
                accountTextBox.Focus();
            }
        }
        private void closeBtn_Click(object sender, EventArgs e)
        {
        }
    }
}
2012-01-08 15:35
wypdragon
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:29
专家分:110
注 册:2011-11-19
收藏
得分:20 
在form3的构造函数中加上这句
this.Load += new System.EventHandler(this.loginForm_Load);
加完后就是这样:
程序代码:
            // 
            // loginForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(243, 191);
            this.Controls.Add(this.closeBtn);
            this.Controls.Add(this.loginBtn);
            this.Controls.Add(this.passwTextBox);
            this.Controls.Add(this.accountTextBox);
            this.Controls.Add(this.passwLabel);
            this.Controls.Add(this.accountLabel);
            this.Name = "loginForm";
            this.Text = "登录窗口";
            this.Load += new System.EventHandler(this.loginForm_Load);
            (()(this.权限管理DataSet)).EndInit();
            (()(this.权限管理BindingSource)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();
2012-01-08 16:40
kidangel666
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:139
注 册:2010-9-15
收藏
得分:0 
谢谢
2012-01-08 17:12
快速回复:请教一个关于用dataset搜索数据问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049036 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved