欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

基于C#实现简单的随机抽奖小程序

程序员文章站 2022-04-10 09:49:26
废话不多说了,直接给大家贴代码了。具体代码如下所示: using system; using system.collections.generic; usin...

废话不多说了,直接给大家贴代码了。具体代码如下所示:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.threading.tasks;
using system.windows.forms;
using system.data.sqlclient;
namespace choujiang
{
 public partial class form1 : form
 {
 public form1()
 {
 initializecomponent();
 }
private void button1_click(object sender, eventargs e)
 {
 int number = convert.toint32(textbox1.text.tostring());
 string prize=combobox1.text.tostring();
 string conn = "";
 string sql = "";
 string s = "";
 conn = "server=xtflz-pc;database=xtf;uid=sa;pwd=123456";
 sql = "select *from ticket";
 sqlconnection myconn = new sqlconnection(conn);
 myconn.open();
 sqldataadapter sda = new sqldataadapter(sql,myconn);
 dataset ds=new dataset();
 sda.fill(ds,"ticket");
 datagridview11.datasource = ds;
 datagridview11.datamember = "ticket";
 random rd = new random();
 for (int i = 0; i < number; i++)
 {
 int tmp = rd.next(1, 5);
 s += datagridview11.rows[i].cells["workerid"].value.tostring() +
 datagridview11.rows[i].cells["name"].value.tostring() + "\n";
 }
 messagebox.show("恭喜\n"+s+"\n获得"+prize);
 myconn.close();
 }
 }
}

以上代码就是实现抽奖小程序的全部代码,代码简单易懂,写的不好还请见谅,有好的意见欢迎留言,谢谢大家一直以来对网站的支持。