1

I am working on website and I want upload data to a database that I have connected to in app.aspx.cs

I am encountering the below error every time I start the app:

Error CS0149 Method name expected PoshaWeb C:\Users\zatoo\Desktop\Pusha\workweb\PoshaWeb\App.aspx.cs 35 Active

This is my code:

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(); } } } 

The problem I have is that the variable s is not working inside the if statement.

7
  • 1
    FYI There isn't an a in JSON Commented Aug 1, 2018 at 9:43
  • also if (s("type").ToString = "addstudent") should be if (s("type").ToString == "addstudent") Commented Aug 1, 2018 at 9:46
  • 1
    This whole thing is kinda messed up. You can't just write to the response of a web form like that, not in PageLoad anyway. It's very unclear what you want to do here Commented Aug 1, 2018 at 9:46
  • 1
    You should also read about using and why you need to use it. Memory Leaks C# Commented Aug 1, 2018 at 9:47
  • Consider using the using statement to dispose your SqlConnection and SqlCommand - see stackoverflow.com/questions/75401/… Commented Aug 1, 2018 at 9:48

1 Answer 1

0

As others stated, you could do with reading up using the links provided then go at this again. The fix to your issue is because you're using a method group rather than invoking the actual method call.

if (s("type").ToString = "addstudent") 

Should be

if (s("type").ToString() == "addstudent") 

This will solve the issue you're having, but there are more issues in your code than just this.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.