保存和检索用户信息

编程入门 行业动态 更新时间:2024-10-11 01:18:36
本文介绍了保存和检索用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在此,用户将在相关文本框中输入员工ID,姓名和薪水信息,然后按保留".当用户按下保持"按钮时,员工数据将保存到下一个组合框. 因此,如果用户输入三个雇员的信息,则会在组合框的下拉列表中添加三个雇员的姓名. 输入多个雇员的信息后,用户将从组合框的下拉列表中选择特定雇员,然后按显示"按钮,所选雇员的所有信息(Id,姓名,薪水)将以以下格式显示在消息框中: 员工信息: 编号:001 名称:alman 工资:1000

Here, user will enter employee Id, Name and Salary information in the related textboxes and press "Keep it". When user press "Keep it" button employee data will be saved to the next Combobox. So, if user enters three employees information, three employees’ name will be added in the drop down list of Combobox. After entering several employees’ information, user will select a particular employee from the drop down list of Combobox and press "Show" button, all information (Id, Name, Salary) of the selected employee will be displayed in the messagebox as following format: Employee Information: Id:001 name:alman Salary:1000

namespace WindowsApplicationPraticeOne { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string id; private string name; private double salary; private void keepItbutton_Click(object sender, EventArgs e) { id = idtextBox.Text; name = nametextBox.Text; salary =Convert.ToDouble(salarytextBox.Text); employecomboBox.Items.Add(name); } private void showbutton_Click(object sender, EventArgs e) { } } }

推荐答案

将此类设为Employee类 make a class Employee like this class Employee { public string Id; public string Name; public double Salary; }

现在拿一个哈希表

now take a hash table

HashTable hsEmp=new HashTable();

现在将您的代码更改为

now change your code as

private void keepItbutton_Click(object sender, EventArgs e) { Empolyee objEmp=new Employee(); objEmp.id = idtextBox.Text; objEmp.name = nametextBox.Text; objEmp.salary =Convert.ToDouble(salarytextBox.Text); hsEmp.Add(objEmp.Name,objEmp); employecomboBox.Items.Add(name); } private void showbutton_Click(object sender, EventArgs e) { Employee objEmp=hsEmp[cboEmp.SelectedValue]; // write code to show employee data; }

--Pankaj

--Pankaj

Class Emp { string id; string name; doubl sal; } namespace WindowsApplicationPraticeOne { public partial class Form1 : Form { public Form1() { InitializeComponent(); } IDictionary empDic<string,emp> = new Dictionary<string,emp>(); private void keepItbutton_Click(object sender, EventArgs e) { Emp temp=new Emp() temp.id = idtextBox.Text; temp.name = nametextBox.Text; temp.salary =Convert.ToDouble(salarytextBox.Text); employecomboBox.Items.Add(temp.name); empDic.add(temp.id,temp); } private void showbutton_Click(object sender, EventArgs e) { Emp temp2 = empDic[employecomboBox.SelectedText.toString()]; //Now you have you can use temp2 class to display data } } }

P.S. :我尚未编译和测试代码,但应该可以正常工作

P.S. : I have not compiled and tested the code but should work

private void buttonKeepIt_Click(object sender, EventArgs e) { comboxEmpList.Add.Items(textBoxName.Text); //If you are using the database as MySql then use this query to store //MySql code: insert into Emptable(id,name,salary) values("18","YYY","28487.87"); } private void buttonShow_Click(object sender, EventArgs e) { string selectedEmpName = comboboxEmpList.Text; //If you are using the database as MySql then use this query to store //MySql code: slect * from Emptable where name = selectedEmpName; //Use MySql Adapter to get datatable or dataset textBoxName.Text = dataTable.Rows[0]["name"].ToString(); textBoxid.Text = dataTable.Rows[0]["id"].ToString(); textBoxSalary.Text = dataTable.Rows[0]["salary"].ToString(); }

更多推荐

保存和检索用户信息

本文发布于:2023-11-06 08:32:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563203.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户信息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!