| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 793 人关注过本帖
标题:[求助]觉的winform和数据库方面的增、删、改、查不是很清楚
只看楼主 加入收藏
weiruan007
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-10-29
收藏
 问题点数:0 回复次数:3 
[求助]觉的winform和数据库方面的增、删、改、查不是很清楚
觉的winform和数据库方面的增、删、改、查不是很清楚
哪位有实例或者代码的发给我看看,谢谢了
搜索更多相关主题的帖子: 数据库 winform 
2005-10-29 17:40
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 

private void button2_Click(object sender, System.EventArgs e)
{
this.sqlInsertCommand2.Parameters["@Id"].Value=textBox1.Text;
this.sqlInsertCommand2.Parameters["@name"].Value=textBox2.Text;
this.sqlInsertCommand2.Parameters["@Sex"].Value=textBox3.Text;
this.sqlInsertCommand2.Parameters["@Age"].Value=textBox4.Text;
this.sqlInsertCommand2.Parameters["@Telephone"].Value=textBox5.Text;
this.sqlInsertCommand2.Parameters["@Code"].Value=textBox6.Text;
this.sqlInsertCommand2.Connection.Open();
this.sqlInsertCommand2.ExecuteNonQuery();
this.sqlInsertCommand2.Connection.Close();
this.sqlConnection1.Open();
this.sqlDataAdapter2.Fill(this.dataSet11);
this.sqlConnection1.Close();
this.dataGrid1.Update();
this.dataGrid1.Refresh();
this.textBox1.Text="";this.textBox2.Text="";
this.textBox3.Text="";this.textBox4.Text="";
this.textBox5.Text="";this.textBox6.Text="";

}

private void button1_Click(object sender, System.EventArgs e)
{
this.sqlDeleteCommand3.CommandText="delete from 表名where Id='"+this.textBox12.Text.Trim()+"'or Name='"+this.textBox11.Text.Trim()+"'or Sex='"+this.textBox10.Text.Trim()+"'or Age='"+this.textBox9.Text.Trim()+"'or Telephone='"+this.textBox8.Text.Trim()+"'or Code='"+this.textBox7.Text.Trim()+"'";
this.sqlDeleteCommand3.Connection.Open();
this.sqlDeleteCommand3.ExecuteNonQuery();
this.dataSet11.Clear();
this.sqlDataAdapter1.Fill(this.dataSet11);
this.sqlDeleteCommand3.Connection.Close();
this.textBox12.Text="";this.textBox11.Text="";
this.textBox10.Text="";this.textBox9.Text="";
this.textBox8.Text="";this.textBox7.Text="";
}

private void button3_Click(object sender, System.EventArgs e)
{

if(radioButton1.Checked==true)
{
this.sqlSelectCommand3.CommandText="select * from 表名 where Id='"+this.textBox13.Text.Trim()+"'";
}
else if(radioButton2.Checked==true)
{

this.sqlSelectCommand3.CommandText="select * from 表名 where Name='"+this.textBox13.Text.Trim()+"'";
}
this.sqlConnection1.Open();
this.sqlSelectCommand3.ExecuteNonQuery();
this.dataSet11.Clear();
this.sqlDataAdapter3.Fill(this.dataSet11);
this.dataGrid1.DataSource=this.dataSet11;
this.sqlSelectCommand3.Connection.Close();
if(this.dataSet11.Tables[0].Rows.Count>0)
{
MessageBox.Show("查找成功!","系统提示。",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("查找不成功!","系统提示。",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
this.textBox13.Text="";
}

private void button4_Click(object sender, System.EventArgs e)
{

myBind.Position=0;

}

private void button7_Click(object sender, System.EventArgs e)
{
myBind.Position=myBind.Count-1;
}

private void button5_Click(object sender, System.EventArgs e)
{
if(this.myBind.Position==0)
{
MessageBox.Show("已经是第一条记录了","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
myBind.Position=myBind.Position-1;
}

}

private void button6_Click(object sender, System.EventArgs e)
{
if(myBind.Position==myBind.Count-1)
{
MessageBox.Show("已经是最后一条记录了","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
this.myBind.Position=this.myBind .Position +1;
}

}


<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2005-10-30 13:43
bceric
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2005-9-14
收藏
得分:0 

拜托 给点说明好吗
“唐伯猫” 既然想方便大家,那就别和大家客气


2005-10-30 14:14
cfchhh
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2005-5-8
收藏
得分:0 

我给你一个取数据的例子(其他的自己参照msdn想想怎么做)
在winform上拉一个textBox控件,现在命名空间里加using system.Data.SqlClient
再在winform的pageload事件里加
SqlConnection conn = new SqlConnection();
SqlCommand cmm = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
conn.ConnectionString = st2;
cmm.Connection = conn;
cmm.CommandText = "select * from huhh";
da.SelectCommand = cmm;
da.Fill(ds,"huhh");
conn.Close();
cmm.Dispose();
this.textBox.text = ds.Tables["huhh"].Rows[i][j].ToString().Trim()//这里把表huhh的第i行第j列的数值付给textbox,这里i,j你可以自己指定


2005-10-31 11:34
快速回复:[求助]觉的winform和数据库方面的增、删、改、查不是很清楚
数据加载中...
 
   



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

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