c# 中,怎么将绑定的数据源做成类?

来源:百度知道 编辑:UC知道 时间:2024/06/29 23:47:09
string stu_cx1 = "";
SqlConnection Sqlconn = new SqlConnection();
Sqlconn.ConnectionString = "Data Source=(local);Initial Catalog=students;Integrated Security=SSPI;";
SqlCommand Sqlcmd = new SqlCommand();
Sqlcmd.Connection = Sqlconn;
string stu_cx = "";
if (textBox1_name.Text.Replace(" ", "") != "" || comboBox1_sex.Text.Replace(" ", "") != "" || comboBox2_class.Text.Trim() != "" || textBox3_adr.Text.Replace(" ", "") != "" || textBox4_email.Text.Replace(" ", "") != "" || textBox5_phone.Text.Replace(" ", "") != "" || Class1.getA != "")
{
stu_cx = stu_cx + "where ";
if (textBox1_name.Text.Replace(" ", "")

那就写成类呗。。定义一个静态类。。。把上面内容放进去呗。。。有什么难的。。
你的意思是不是 写成一个方法啊?

一堆垃圾代码,应该写到数据层的,单例模式中去……

看你这是C#吧,写成一个class文件不就可以了吗?或者你到网上搜索数据库访问类。一大堆

你是要把他写成一个基类
还是要将你现在写的方法封装起来 类似DBHelper呢

public static DataSet Select(string a,string b)
{
string stu_cx1 = "";
SqlConnection Sqlconn = new SqlConnection();
Sqlconn.ConnectionString = "Data Source=(local);Initial Catalog=students;Integ