我正在网站上,我想将数据上传到我在app.aspx.cs
中已连接的数据库中
每次启动应用程序时都会遇到以下错误:
错误CS0149方法名称预期为PoshaWeb C:\ Users \ zatoo \ Desktop \ Pusha \ workweb \ PoshaWeb \ App.aspx.cs 35有效
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Configuration;
namespace PoshaWeb
{
public partial class App : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Stream body = Context.Request.InputStream;
System.Text.Encoding Encoding = Context.Request.ContentEncoding;
StreamReader reader = new StreamReader(body, Encoding);
String inJson = reader.ReadToEnd();
var s = Newtonsoft.Json.JsonConvert.DeserializeObject(inJson);
System.Data.SqlClient.SqlConnection Conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["MyPoshDB"].ConnectionString);
Conn.Open();
System.Data.SqlClient.SqlCommand Comm = new System.Data.SqlClient.SqlCommand
{
Connection = Conn
};
try
{
if (s("type").ToString = "addstudent")
{
Comm.CommandText = "INSERT INTO Members (MemName, MemMobile, MemEmail, MemID, MemGovID, MemDocURL, MemPicURL) VALUES(N'" + s("name").ToString + "', N'"+ s("mobile").ToString + "', N'" + s("email").ToString + "', N'" + s("recordnumber").ToString + "', N'" + s("idnumber").ToString + "', N'" + s("picturepath").ToString + "', N'" + s("documentpath").ToString + "')";
Comm.ExecuteNonQuery();
Response.Write("{\"result\":\"success\"}");
}
}
catch (Exception ex)
{
Page.Response.Write("{\"result\":\"fail\",\"desc\":" + Newtonsoft.Json.JsonConvert.SerializeObject(ex.Message) + "}");
}
Conn.Close();
}
}
}
我遇到的问题是变量s
在if
语句中不起作用。
答案 0 :(得分:0)
正如其他人所述,您可以使用提供的链接进行阅读,然后再次进行操作。解决此问题的方法是,因为您使用的是方法组,而不是调用实际的方法调用。
if (s("type").ToString = "addstudent")
应该是
if (s("type").ToString() == "addstudent")
这将解决您遇到的问题,但是您的代码中不仅有这个问题。