나는 잠시 동안 노력했지만 실제로 이해하지 못합니다. 나는 "암시 적으로 'void'를 'string'으로 암시 적으로 변환 할 수 없습니다." 문자열, int, 무효, 무효, 공용, 정적 및 기타 여러 변형을 시도했습니다.암시 적으로 'void'유형을 'string'으로 변환 할 수 없습니다.
나는 내 DAL과 BLL 내 db thoug에서 하나의 가치를 얻고 싶습니다, 내 코드는 다음과 같습니다.
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Repeater1.DataSource = BLL.getGames();
Repeater1.DataBind();
var culture = CultureInfo.GetCultureInfo("sv-SE");
var dateTimeInfo = DateTimeFormatInfo.GetInstance(culture);
var dateTime = DateTime.Today;
int weekNumber = culture.Calendar.GetWeekOfYear(dateTime, dateTimeInfo.CalendarWeekRule, dateTimeInfo.FirstDayOfWeek);
string mroundY = dateTime.Year.ToString();
string mroundW = weekNumber.ToString();
string mrounddate = mroundY + mroundW;
string mround = BLL.getMroundGames(mrounddate); <-- Here's the error
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
}
}
내 BLL은 다음과 같습니다.
public class BLL
{
public static void getMroundGames(string mrounddate)
{
SqlCommand getMroundGames = new SqlCommand("SELECT mround FROM gameTB where mround = @mrounddate");
DAL.ExecuteNonQuery(getMroundGames);
}
}
또한 시도해보십시오.
public class BLL
{
public static DataTable getMroundGames(string mrounddate)
{
SqlCommand getMroundGames = new SqlCommand("SELECT mround FROM gameTB where mround = @mrounddate");
getMroundGames.Parameters.Add("@mrounddate", SqlDbType.VarChar, 10).Value = mrounddate;
return DAL.GetData(getMroundGames);
}
}
마지막으로 내 DAL은 이렇게 보입니다.
public class DAL
{
public static SqlConnection GetConnection()
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["tiptopConnectionString"].ConnectionString);
conn.Open();
return conn;
}
public static DataTable GetData(SqlCommand command)
{
try
{
using (SqlConnection conn = GetConnection())
{
using (DataSet ds = new DataSet())
{
using (SqlDataAdapter da = new SqlDataAdapter())
{
da.SelectCommand = command;
da.SelectCommand.Connection = conn;
da.Fill(ds);
return ds.Tables[0];
}
}
}
}
catch (Exception err)
{
throw new ApplicationException(string.Format("Felmeddelande:{0}", err.Message));
}
}
public static object ExecuteScalar(SqlCommand command)
{
using (SqlConnection conn = GetConnection())
{
command.Connection = conn;
object result = command.ExecuteScalar();
return result;
}
}
public static void ExecuteNonQuery(SqlCommand command)
{
using (SqlConnection conn = GetConnection())
{
command.Connection = conn;
command.ExecuteNonQuery();
}
}
}
시작하는 부분?
귀하의 기능은 '무효'즉 아무것도 반환하지 않습니다. 그리고 그것을 문자열에 할당하려고합니다 ... 당신은 무엇을 기대합니까? – Floris
왜 당신은 무효로 돌아오고 있습니까? –
물건을 세게 만드는 대신에 좋습니다. 어떻게하면 aspx 페이지에 단일 값을 표시 할 수있는 간단한 쿼리를 수행 할 수 있습니까? 여기서 mround = 현재 연도의 현재 주. 그래서 SQL은 다음과 같습니다. mround에서 gameTB 선택 mround = 201310 그리고 mroundlabel이라는 ID로 내 라벨에 sql 값을 가져 왔습니까? – Slint