主题:求助 ADO.NET
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Collections;
using System.Data;
namespace StuElective.model
{
public static class SQLHelp
{
private static SqlConnection con = new SqlConnection("server=.;database=stuIonf;uid=sa;pwd=sa;");
private static SqlCommand cmm = con.CreateCommand();
public static bool update(string str)
{
cmm.CommandText = str;
con.Open();
int count =cmm.ExecuteNonQuery() ;
cmm.Parameters.Clear();
con.Close();
if (count > 0)
{
return true;
}
else
{
return false;
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using StuElective.model;
using StuElective.center;
namespace StuElective
{
public partial class Laoding : Form
{
public Laoding()
{
InitializeComponent();
}
private void Laod_Click(object sender, EventArgs e)
{
if (SQLHelp.update("insert Students values('da','dsf','as')"))
{
MessageBox.Show("选课成功!!");
}
}
}
}
这代码 有什么问题?
为什么 运行不出来?
急!!!!
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Collections;
using System.Data;
namespace StuElective.model
{
public static class SQLHelp
{
private static SqlConnection con = new SqlConnection("server=.;database=stuIonf;uid=sa;pwd=sa;");
private static SqlCommand cmm = con.CreateCommand();
public static bool update(string str)
{
cmm.CommandText = str;
con.Open();
int count =cmm.ExecuteNonQuery() ;
cmm.Parameters.Clear();
con.Close();
if (count > 0)
{
return true;
}
else
{
return false;
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using StuElective.model;
using StuElective.center;
namespace StuElective
{
public partial class Laoding : Form
{
public Laoding()
{
InitializeComponent();
}
private void Laod_Click(object sender, EventArgs e)
{
if (SQLHelp.update("insert Students values('da','dsf','as')"))
{
MessageBox.Show("选课成功!!");
}
}
}
}
这代码 有什么问题?
为什么 运行不出来?
急!!!!