我继承了1页的Web应用程序进行更新,旧的经典ASP版本使用了LEFT,RIGHT和MID功能。更新的应用程序使用C#ASP.NET。有没有办法导入VB左,右和中功能或模拟这些功能的功能。
如果字符串比C#下的length参数短,则C#substring函数似乎返回错误。 (不要取笑我的C#代码,我几乎不使用C#)。填写所需的代码将是非常棒的
<%@ Page language="c#" %>
<%@ Import namespace="Microsoft.VisualBasic"%>
<script runat="server" language="C#">
protected virtual string Auth(string uid)
{
String xml;
if (!String.IsNullOrEmpty(Request["uid"]))
{
System.Data.DataTable dtTable = new System.Data.DataTable();
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
conn.Open();
string query = "SELECT id, blah, blah from users WHERE left(secretkey,30)='" + Request["uid"] + "'"; <--need to know how to use left function here
blah blah blah...
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>blah</title>
</head>
<body>
<form id="Form1" method="post" runat="server"><% Page_Load(null, null); %></form>
</body>
</html>
答案 0 :(得分:1)
就像我在关于这个问题的评论中已经说过的那样,你正在使用SQL的left
函数,所以如果你使用的是vb或c#并不重要。
答案 1 :(得分:0)
检查此链接..它包含一些方法,您可以使用它们等同于c#中左侧,中间,右侧的vb http://devexpp.blogspot.in/2012/04/c-left-mid-and-right-functions.html
答案 2 :(得分:0)
来自我评论中的链接问题,
Left() = "string".Substring(0, length)
Right() = "string".Substring("string".Length - desiredLength)
Mid() = "string".Substring(start, length)
答案 3 :(得分:0)
第一个问题是您在此示例中根本没有在C#中调用左键。
string query =“SELECT id,blah,blah from users WHERE left(secretkey,30)='”+ Request [“uid”] +“'”;
您正在使用sql server中的left函数,这就是您在网页中没有收到任何错误的原因,请参阅http://msdn.microsoft.com/en-us/library/ms177601.aspx
第二个问题是表中的密钥,所以除非你将它的值检索到客户端,否则你永远不能使用VB的左边函数
所以我假设这只是一个非常糟糕的例子,你正在寻找更像这样的东西。
var secretkey =“ABCDEFGHIJKLMNOP”
string query =“选择blah,blah from users Where secretkey =”+ secretkey.Substring(0,30)