-1
我已經遍尋搜索,但無法弄清楚這裏有什麼問題。我有一個webb c#應用程序。我有一個c#方法在我查詢數據庫的應用程序文件夾中,然後想要將該值傳遞迴我的Cshtml頁面,在那裏我將根據值進行makin deciaions。不糾結我做什麼,當我打電話的方法,然後嘗試讀取我的錯誤「無法鍵入‘1類’隱式轉換爲字符串值。從CSHTML文件中調用另一個類的方法
這裏是我的C#類的方法和下面的電話
方法:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public class class1
{
public static string getdata()
{
string cnnString = ConfigurationManager.ConnectionStrings["GDC_WellsFargoConnectionString"].ConnectionString;
SqlDataReader reader;
string returnValue;
/// var cmd = "insert into Email Insert values(@name,@email";
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
using (SqlConnection cnn = new SqlConnection(cnnString))
{
using (SqlCommand cmd = new SqlCommand("Select isnull([Authorization],'none') as authoriztion from PNSWebAuthorization where username = '" + userName + "'", cnn))
{
////cmd.Parameters.AddWithValue("@name", "Newname,First");
//// cmd.Parameters.AddWithValue("@email", "[email protected]");
///string authcode;
cnn.Open();
try {
reader = cmd.ExecuteReader();
if (reader.Read())
{
returnValue = reader["Authorization"].ToString();
reader.Close();
return returnValue;
}
else
{
reader.Close();
return "";
}
}
catch (Exception err)
{
throw new ApplicationException(err.Message);
}
finally
{
cnn.Close();
cnn.Dispose();
}
}
}
}
CSHTML Calling
@model GDC.Finance.WebClient.Areas.Treasury.ViewModels.CashReceiptSessionListViewModel
@using PagedList.Mvc;
@{
ViewBag.Title = "Cash Receipt Sessions test";
}
<h2>Sessions</h2>
@section scripts{
<script src="~/Scripts/popup.js"></script>
}
@{
/// string auth = "none";
var auth = new class1();
class1.getdata();
string rights = auth;
}
Auth throws the error.
我會試一試 – Janf
這個工作完全謝謝你 – Janf