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.
if (s("type").ToString = "addstudent")should beif (s("type").ToString == "addstudent")usingand why you need to use it. Memory Leaks C#usingstatement to dispose yourSqlConnectionandSqlCommand- see stackoverflow.com/questions/75401/…