Question about a cose I need to alter

Posted by Bezacom under ASP.NET on 6/8/2014 | Points: 10 | Views : 379 | Status : [Member] | Replies : 1
Hey guys,

I'm new here and I have a question.

I have this code and I need to remove the part where it adds the information to the DB.

I tried many things (without knowing html), but none worked.

I think, this line " DB.Instance.InsInfo(info);" is the one who enters the data to the DB but i couldn't make it work without it.

Please HELP!

Thanks!!

Jason.



using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

public partial class Main : BasePage
{
public class ShowResult
{
public string Type { get; set;}
public string Value { get; set;}
public string Action { get; set; }

public ShowResult(string type, string value, string action)
{
Type = type;
Value = value;
Action = action;
}
}

protected void Page_Load(object sender, EventArgs e)
{
if (CurrentUser == null)
{
Response.Redirect("Login.aspx");
}
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
List<ShowResult> showResult = new List<ShowResult>();
string allInfo = txtInfo.Text;
var separator = new[] {"\r\n"};
var inputArray = allInfo.Split(separator,StringSplitOptions.None);
foreach (var s in inputArray)
{
Info info = new Info();
info.UserId = CurrentUser.Id;
info.Type = s.Contains("@") ? "Email" : "Domain";
if (info.Type.Equals("Domain"))
{
if (s.Contains("http://www."))
{
info.Value = s.Substring(11, s.Length - 11);
}
else if (s.Contains("http://"))
{
info.Value = s.Substring(7, s.Length - 7);
}
else if (s.Contains("www."))
{
info.Value = s.Substring(4, s.Length - 4);
}
else
{
info.Value = s;

}

}
else
{
info.Value = s;
}

var new_s = info.Value.Split('/');
info.Value = new_s[0];
var res = DB.Instance.InsInfo(info);
if (res =="1")
{
showResult.Add(new ShowResult(info.Type,info.Value,"Approved"));
}
else if (res == CurrentUser.Username)
{
showResult.Add(new ShowResult(info.Type, info.Value, "Exist by: " + CurrentUser.Username));
}
else
{
showResult.Add(new ShowResult(info.Type, info.Value, "Exist by: " + res));
}

}

grdResults.DataSource = showResult;
grdResults.DataBind();
}

protected void grdResults_OnRowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label action = (Label)e.Row.FindControl("lblAction");

if (action.Text.Contains("Approved"))
{
action.Style["background-color"] = "green";
//action.Style["color"] = "white";
}
else if (action.Text.Contains(CurrentUser.Username))
{
action.Style["background-color"] = "yellow";
//action.Style["color"] = "white";
}
else
{
action.Style["background-color"] = "red";
}



}

}
}





Responses

Posted by: Sheonarayan on: 6/10/2014 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
If you comment that line of code, it will ask for res variable so do something like this.

var res = string.Empty; // DB.Instance.InsInfo(info);


In this way, the variable res is still there but its value is empty. So the record into the database will not be entered and your code will still function.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Bezacom, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response