REG:C#窗口表单和数据库连接 [英] REG:C# Window form and database connection

查看:115
本文介绍了REG:C#窗口表单和数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以c#Windows形式保存按钮需要什么代码才能保存到SQL数据库中?

What is code need to give for save button in c# windows form to saving in SQL database

推荐答案

sqlconnection conn=new sqlconnection();
sqlcommand cmd=new sqlcommand();
string query="insert into tablename(column1,column2) values(''column1 value'',''column2 value'') ";
cmd.connection=conn;
cmd.commandtext=query;
conn.open();
cmd.executenonquery();
conn.close;


string s = "INSERT into UserDetails values(''" + txtemail.Text + "'',''" + txtfirstname.Text + "'',''" + txtlastname.Text + "'',''" + txtpwd.Text + "'',''" + ddlcountry.SelectedItem.Text + "'',''" + ddlstate.SelectedItem.Text + " '',''" + txtcity.Text + "'',''" + txtphnumber.Text + "'',''" + txtaddress1.Text + "'',''" + txtaddress2.Text + "'',''" + txtqualification.Text + "'',''" + txtskills.Text + "'')";
            SqlCommand cmd;
            cn = new SqlConnection(conection.getconnection());
            cmd = new SqlCommand(s, cn);
            cn.Open();
            cmd.ExecuteNonQuery();
            cn.Close();


这篇关于REG:C#窗口表单和数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆