hoyong

导航

Show() 与 ShowDialog()区别

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;
using System.Data.SqlClient;

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

private void button1_Click(object sender, EventArgs e)
{
//显示另外一个窗体
//Form2 f2 = new Form2();
//f2.Show();//这种方式,原窗口可以获得焦点
//模态显示窗体
//Form2 f2 = new Form2();
//DialogResult dr= f2.ShowDialog();//原窗口不可以获得焦点,除非此窗口关闭,同时会向父窗口返回一个值
//if (dr == DialogResult.Yes)
//{
// MessageBox.Show("OK");
//}
}

private void button2_Click(object sender, EventArgs e)
{
string connStr = "Data Source=(local);Initial Catalog=hem09;User ID=sa;Password=123456;Fooling=false";
using (SqlConnection conn = new SqlConnection(connStr))
{
string sql = "select count(*) from department where dname='a2'";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
int rows = int.Parse(cmd.ExecuteScalar().ToString());
if (rows > 0)
{
//查找了
}
else
{
//没找着
}
}
}
}
}

 

***************************************************************************************

 

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 T1_UserManage
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Yes;//设置这个窗口的返回值,只有父窗口采用ShowDialog()方式打开此窗口时,才有效
}
}
}

 

***************************************************************************************

 

 

select count(*) from aa where uname='' and upwd=''
加在select 语句后面,用于区分大小写collate Chinese_PRC_CS_AI

posted on 2015-07-08 22:36  hoyong  阅读(184)  评论(0)    收藏  举报