我有共同的错误 [英] I got Error in Common
本文介绍了我有共同的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
Dear All,
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class DataReaderFromSql : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataReaderFromSqlAccess();
}
public void DataReaderFromSqlAccess()
{
string strSql = "Select * from Emp_Details";
try
{
using (SqlConnection cnn = new SqlConnection(
Common.GetConnectionString("SqlConnectionString")))
{
using (SqlCommand cmd = new SqlCommand(strSql, cnn))
{
cnn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
AccessList.Items.Add(String.Format("{0} {1}",
dr["empid"], dr["password"]));
}
}
}
}
}
catch (Exception ex)
{
errorLabel.Text = ex.Message;
}
}
}
如何解决此错误:我在通用"附近遇到错误,当前竞赛中不存在
How to resolve this error: i got error near the Common, does not exists in current contest
推荐答案
您尚未将名称空间包括在包含通用"的类中. br/> 右键单击常见",然后查看是否有解决方案.用那个.
如果不理解,很可能您需要添加对该dll的引用.
You have not included the namespace to the class that includes Common.
Right click on Common and see if you get a resolve option. Use that.
If you don''t get it, mostly likely you need to add a reference to the dll.
您在通用"附近遇到了哪个错误?
最好使用ConfigurationManager来获取连接字符串并将连接字符串存储到connectionString标记中的Web.Config文件中
Which error you got near Common?
Better use ConfigurationManager to get Connection String and store your connection String into Web.Config file in connectionString tag
顺便说一句,普通是阶级,也许它不存在:)
您在连接字符串中遇到的问题尝试像这样使用它.
Hi ,
BY THE WAY Common is class and maybe it doesn''t exist :)
your problem in connection string try to use it like this.
<connectionStrings>
<add name="testConnectionString" connectionString="Data Source=.;Initial Catalog=test;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
背后的代码
Code Behind
protected void Page_Load(object sender, EventArgs e)
{
DataReaderFromSqlAccess();
}
public void DataReaderFromSqlAccess()
{
string strSql = "Select * from Emp_Details";
try
{
using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString)
)
{
using (SqlCommand cmd = new SqlCommand(strSql, cnn))
{
cnn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
xxx =(String.Format("{0} {1}",
dr["empid"], dr["password"]));
}
}
}
}
}
catch (Exception ex)
{
// errorLabel.Text = ex.Message;
}
}
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于我有共同的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文