解决方案 »
- 求助:要写一个编号,编号格式如:OA_110_12_0001号
- C#里的sql语句如何得到昨天,今天?在线等
- 急求HttpWebRequest 登录网页hotmail源码或者大家一起讨论一下!
- 有关WinForm C#中的错误!
- c#中如何将一个datetime的年月日部分转为int
- 怎么才能学好.NET技术呢 ?
- 寻找高手,用C#代码控制POS打印时,是否打开钱箱问题?
- datagrid问题
- 急!!遇到一个关于TableAdapter中insert无效的问题。
- 怎样使用asp.net作为客户端远程调用com+!!!能给小弟发一个例子最好!!![email protected]
- c# webbrowser 加载网页后点击按钮
- C#socket编程的BeginReceive会阻塞吗?
一步一步的,先用Console.WriteLine()提示用户现在要输入什么了,然后用户输入完读出来放变量里
//定义一个静态公关全局变量
public static int MyKahao; private void button1_Click(object sender, EventArgs e)
{
//第一步:指定连接的数据库
SqlConnection conn= new SqlConnection("server=HHY-PC\\HHY;uid=sa;pwd=123456;database=YangATM_DB"); //第二步:需要执行的SQL语句
string sql = "select * from KaiHuInFo where KaHao='" + txtkahao.Text + "' and KaMiMa='" + txtmima.Text + "'"; //第三步:申明一个数据适配器用于解析SQL语句的,且开始解析SQL语句
SqlDataAdapter da = new SqlDataAdapter(sql, conn); //第四步:申明一个数据集
DataSet ds = new DataSet();
//Console.WriteLine("请输入卡号");
//第五步:将查询的结果存放到数据集中
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
MessageBox.Show("登录成功");
//获取文本框内的值并赋值
MyKahao = Convert.ToInt32(txtkahao.Text);
QuKuanJianMian qk = new QuKuanJianMian();
qk.Show(); this.Hide();
}
else
{
MessageBox.Show("输入的账号或密码不正确");
txtkahao.Text = "";
txtmima.Text = "";
}
而你现在本身就是把代码直接放到按钮事件里去,而控制台里根本没有所谓按钮事件,那么不改势必是不可能的
void function(string text1,string text2){}
然后针对不同的项目,两个字符串从哪里来不一样而已,最终都是传入字符串之后调用函数
否则你整个代码已经跟控件耦合在一起,不改不行的
你们有没有完成的控制台ATM已经连接好的数据库,最好是vs2010打开的 谁有请发我一份 我有较多积分供你们下载其他资料
{
static void Main(string[] args)
{
string userInput="";
Console.WriteLine("Please input your Account:");
userInput = Console.ReadLine();
int iAccount = -1;
if(!int.TryParse(userInput, out iAccount))
{
Console.WriteLine("Account is not Correct.");
return;
}
Console.WriteLine("Please input your Password:");
userInput = Console.ReadLine();
if(userInput.Trim().length == 0)
{
Console.WriteLine("Password error.");
return;
}
string password = userInput;
DummyTextBox txtkahao = new DummyTextBox(iAccount + "");
DummyTextBox txtmima = new DummyTextBox(password);
// copy you code here.
}
}class DummyTextBox
{
public DummyTextBox()
{
}
public DummyTextBox(string text)
{
this.Text = text;
}
public string Text;
}
还有,你们密码都是明文存数据库的???!!!!
连接字符串连的数据库希望是测试数据库而不是真正的生产环境,不然直接sa连阿,密码还看得到阿。。最后,console如果要调用messagebox之类的winform的东西,记得加参照
https://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlparameter(v=vs.110).aspx