【求助】C#关于控制台的一个问题!拜托大神帮帮忙了!!!!
在控制台中,我的程序:
Class Program
{
public SqlConnection sqlconn;
public SqlCommand sqlcmd = new SqlCommand();
string strconn;
int numcount;
static void Main(string[] args)
{
Program rm = new Program();
rm.ConnectSQL();
}
public void ConnectSQL()
{
strconn = "server=".\\MYSQLDATABASE;database="TESTDataBase;uid=sa;password=1234";
sqlconn = new SqlConnection(strconn);
sqlconn.open();
sqlcmd.Connection = sqlconn;
sqcmd.CommandText = "Select * from Student_Test";
sqcmd.CommandType = CommandType.Text;
sqcmd.ExecuteNonQuery();
}
}
错误:process is terminated due to stackoverflowException
我打断点看了下是这样子:它总是从main函数中:Program rm = new Program();跳到上面public SqlConnection sqlconn。。。。中,一直无限循环,怎么办????
------解决方案--------------------Class Program
{
private static SqlConnection sqlconn;
private static SqlCommand sqlcmd = new SqlCommand();
private static string strconn;
int numcount;
static void Main(string[] args)
{
ConnectSQL();
}
public static void ConnectSQL()
{
strconn = "server=".\\MYSQLDATABASE;database="TESTDataBase;uid=sa;password=1234";
sqlconn = new SqlConnection(strconn);
sqlconn.open();
sqlcmd.Connection = sqlconn;
sqcmd.CommandText = "Select * from Student_Test";
sqcmd.CommandType = CommandType.Text;
sqcmd.ExecuteNonQuery();
}
}