SqlDataReader dr=Comm.ExecuteReader();
if(dr.Read())
{
dr.Close();
int type;
//MessageBox.Show("suc","jieguo"); SqlCommand Comm2=new SqlCommand("select type from login where name= '" + textBox1.Text + "'and password=" + textBox2.Text,Conn);
SqlDataReader dr2 = Comm2.ExecuteReader();
//type=dr2.GetSqlBoolean(3).ToSqlInt32(); Form2 a =new Form2();
a.Show();
}问题:1:如何简化以上的代码?非得dr.Close();后才进行新的查询吗?2:Comm2查询的sql里对应的bit数据类型,如何把它取出来?我想赋给一个int该怎么做?谢谢
if(dr.Read())
{
dr.Close();
int type;
//MessageBox.Show("suc","jieguo"); SqlCommand Comm2=new SqlCommand("select type from login where name= '" + textBox1.Text + "'and password=" + textBox2.Text,Conn);
SqlDataReader dr2 = Comm2.ExecuteReader();
//type=dr2.GetSqlBoolean(3).ToSqlInt32(); Form2 a =new Form2();
a.Show();
}问题:1:如何简化以上的代码?非得dr.Close();后才进行新的查询吗?2:Comm2查询的sql里对应的bit数据类型,如何把它取出来?我想赋给一个int该怎么做?谢谢
解决方案 »
- 自己没事写了个自己不断切换背景色的Label控件(重载的系统的Label),就是给控件添加个线程,不断切换背景,求优化方法,或者更好的方法,谢谢
- 如何把模板类参数化,然后让不同的namespace调用?
- 如何实现鼠标步进移动?
- C# socket 使用Udp通讯
- 导出excel问题
- 根据XML在TreeListView中添加的节点,为什么顺序会改变
- C#截取文件名称
- 求助:电脑使用中不定时的浮出IE广告。烦人,不知道中了什么恶意代码。帮忙啊!!!!!!!
- 从dataset写入XML文件发生数据丢失
- 谁用C#开发过移动短信接口,用华为的API的。我有一直解决不了的问题。分可以多加。给500分。
- ·····有没有什么方法可以修改诸如MessageBox之类的窗体的外观?·····
- 实现模块的移动
if(dr.Read())
{
dr.Close();
int type; Comm.CommandText="select type from login where name= '" + textBox1.Text + "'and password=" + textBox2.Text;
SqlDataReader dr2 = Comm.ExecuteReader();
Form2 a =new Form2();
a.Show();
}1,datareader取得數據之後,就要關掉!但Command對象可以多次使用.
2,int val=Convert.ToInt32(dr2[index])//使用強制轉換把相應的列轉為整形。
SqlDataReader dr2 = Comm.ExecuteReader();
if(dr2.HasRows==true)
type=Convert.ToInt32(dr2[3]);为什么if可执行但type=Convert.ToInt32(dr2[3]);这句说“在没有任何数据的时候进行无效的读取尝试”?
if(dr.Read())
{
dr.Close();
int type;
Comm.CommandText="select type from login where name= '" + textBox1.Text + "'and password=" + textBox2.Text;
SqlDataReader dr2 = Comm.ExecuteReader();
Form2 a =new Form2();
a.Show();
}
1.datareader每次使用后需要关闭,Command的TEXT可以多次赋值
2.int type=Convert.ToInt32(dr2.GetSqlBoolean(3);
具体可以往上查询 "java bean 数据库连接", 照着改动一下就行.