问题在下面的代码中注释了,请看下面:
这个倒低是什么问题啊!!急求解!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;namespace ConnectStr
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
string connstring = "Data Source=.;initical catalog=MySchool;user ID=sa;Pwd=123";
SqlConnection connection = new SqlConnection(connstring);
string sql = "select count(*) from recordInfo";
connection.Open();
SqlCommand command=new SqlCommand(sql,connection);
int num=(int) command.ExecuteScalar();
if(num>0)
{
这里本来我是想Form2 fr=new Form2(); 可是编译器里都没有Form2的提示;思想是数据库连接成功后就出现Form2这个窗体
}
connection.Close();
} }
}
Form2的窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace 登陆
{
public partial class Form2 : Form
{
//然后这里我本来也是想定义个 Form1 mainform;可是同样的也没有出现Form1这个类
public Form2()
{ InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
}
}
这个倒低是什么问题啊!!急求解!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;namespace ConnectStr
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
string connstring = "Data Source=.;initical catalog=MySchool;user ID=sa;Pwd=123";
SqlConnection connection = new SqlConnection(connstring);
string sql = "select count(*) from recordInfo";
connection.Open();
SqlCommand command=new SqlCommand(sql,connection);
int num=(int) command.ExecuteScalar();
if(num>0)
{
这里本来我是想Form2 fr=new Form2(); 可是编译器里都没有Form2的提示;思想是数据库连接成功后就出现Form2这个窗体
}
connection.Close();
} }
}
Form2的窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace 登陆
{
public partial class Form2 : Form
{
//然后这里我本来也是想定义个 Form1 mainform;可是同样的也没有出现Form1这个类
public Form2()
{ InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
}
}
登陆.From2就可以点出来了
namespace 登陆你的两个窗体没在一个命名空间里,直接写当然不会出来。在Form1的文件里using 登陆,在Form2的文件里using ConnectStr 或者把命名空间改成同一个。另外,你的命名空间最好不要用汉字。
当需要引用的类不再同一命名空间下的时候 需要显示的指出类的命名空间
或者在文件的最上面加上using 引用该命名空间
希望能够帮到你。