Unable to pass parameters to SSRS report in ASP.NET page - asp.net

Hi I am getting an error in supplying parameters to an SSRS report deployed on server in ASP.NET page.
Please refer to the code below and let me know where is the issue?
ReportExecutionService rs = new ReportExecutionService();
string rptURL = System.Configuration.ConfigurationManager.AppSettings["rptURL"].ToString();
string rptPath = System.Configuration.ConfigurationManager.AppSettings["Page1SLScorecardReortForDownload"].ToString();
//Microsoft.Reporting.WebForms.ReportParameter[] paramlist = new Microsoft.Reporting.WebForms.ReportParameter[3];
//paramlist[0] = new Microsoft.Reporting.WebForms.ReportParameter("Week", "2013-05-03");
//paramlist[1] = new Microsoft.Reporting.WebForms.ReportParameter("year", "Fiscal Calendar 2013");
//paramlist[2] = new Microsoft.Reporting.WebForms.ReportParameter("Month", "Fiscal May, 2013");
ParameterValue[] paramlist = new ParameterValue[3];
//Microsoft.Reporting.WebForms.ReportParameter[] paramlist = new Microsoft.Reporting.WebForms.ReportParameter[3];
paramlist[0] = new ParameterValue();
paramlist[0].Name = "Week";
paramlist[0].Value = "2013-05-03";
paramlist[1] = new ParameterValue();
paramlist[1].Name = "year";
paramlist[1].Value = "Fiscal Calendar 2013";
paramlist[2] = new ParameterValue();
paramlist[2].Name = "Month";
paramlist[2].Value = "Fiscal May, 2013";
//ReportViewer1.ServerReport.SetParameters(paramlist);
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = rptURL;
byte[] result = null;
string reportPath = rptPath;
string format = "EXCEL";
string historyID = null;
string devInfo = #"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
string encoding;
string mimeType;
string extension;
ReportingWS.Warning[] warnings = null;
string[] streamIDs = null;
ReportingWS.ExecutionInfo execInfo = new ReportingWS.ExecutionInfo();
ReportingWS.ExecutionHeader execHeader = new ReportingWS.ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);
rs.SetExecutionParameters(paramlist, "en-us");
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
try
{
result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
execInfo = rs.GetExecutionInfo();
}
catch (Exception ex)
{
//AlnErrorHandler.HandleError(ex);
}

parameters.Add(new ReportParameter("FyId", Convert.ToInt16(objSession.FyId).ToString()));
parameters.Add(new ReportParameter("AccountGroupId", cmbAccountGroup.SelectedValue));
parameters.Add(new ReportParameter("LedgerId", cmbLedgerId.SelectedValue));
rptvwMain.ServerReport.SetParameters(parameters);
Pass Parameters like this....

Related

What is ZRangeValid means

This code is to read an excel file, what is ZRangeValid means and what is rs.fields(0).value referring to? Please explain my two questions
var strConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strXLPath + ";Extended Properties=\"Excel 12.0;HDR=YES;\";";
var conn = new ActiveXObject("ADODB.Connection");
conn.open(strConnString, "", "");
var rs = new ActiveXObject("ADODB.Recordset");
var rsrowCount = new ActiveXObject("ADODB.Recordset");
rs = conn.execute("select * from ZRangeValid");
if (rs.fields(0).value != 'YES') {
alert(strXLPath + " requested numbers spreadsheet is not valid.\nPlease validate the spreadsheet data and retry.")
rs = null;
rsSheet = null;
conn.close();
conn = null;
return false
}

Issues on converting the java code to c#

I tried to convert java code into cSharp .I struct on how to encode the data so please help me how to do that..
I tried to pass the values directly without encoding then i got the error as
The remote server returned an error: (400) Bad Request.
if i removed the headers then the error is not coming and i placed the break point in the web site the execution sequence is not stopped at the break point
this is my java code
packagename=encodeData("some value");
username=encodeData("some value");
password=encodeData("some value");
hc= new DefaultHttpClient();
get= new HttpGet("http://techpalle.com/skillgun_App.svc/mobile/papers/"+chap_id+"/app");
get.setHeader(PaperActivity.this.getString(R.string.username),username);
get.setHeader(PaperActivity.this.getString(R.string.password),password);
get.setHeader(PaperActivity.this.getString(R.string.packagename),packagename);
Converted csharp code is
string username=null;
string password=null;
string packagename=null;
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://localhost:2850/TechpalleNew/Skillgun_App.svc/mobile/chapters/" + "16" + "/app");
wr.Headers["username"] = "username";
wr.Headers["password"] = "password";
wr.Headers["packagename"] = "packagename";
WebResponse resp = wr.GetResponse();
StreamReader read = new StreamReader(resp.GetResponseStream());
string res = read.ReadToEnd();
My website code
namespace ISkillgun_App
{
[ServiceContract]
public interface ISkillgun_App
{
[OperationContract]
[System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, UriTemplate = "mobile/chapters/{sub_topic_id}/app")]
List<ChapterNames> Chapters_Names(string sub_topic_id);
[OperationContract]
[System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, UriTemplate = "mobile/papers/{chapter_id}/app")]
List<Paper_Ids> Paper_ids(string chapter_id);
[OperationContract]
[System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, UriTemplate = "mobile/questions/{paper_id}/app")]
List<Qtions_data> Qtions_data(string paper_id);
}
}
namespace Skillgun_App:ISkillgun_App
{
public List<ChapterNames> Chapters_Names(string sub_topic_id)
Breakppoint {
List<ChapterNames> chptrsdetails = new List<ChapterNames>();
using (SqlConnection cn = new SqlConnection(strConnection))
{
using (SqlCommand cmd = new SqlCommand("skillgun_mobile_app_Qtions_data", cn))
{
cmd.CommandType = CommandType.StoredProcedure;
try
{
SqlParameter p1 = new SqlParameter("#type", SqlDbType.VarChar, 20);
SqlParameter p2 = new SqlParameter("#topic_or_paper_id", SqlDbType.Int);
p1.Value = "chapters_data";
p2.Value = sub_topic_id;
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add("#username", SqlDbType.VarChar, 40);
cmd.Parameters["#username"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("#password", SqlDbType.VarChar, 40);
cmd.Parameters["#password"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("#package_name", SqlDbType.VarChar, 50);
cmd.Parameters["#package_name"].Direction = ParameterDirection.Output;
cn.Open();
SqlDataReader drtopics = cmd.ExecuteReader();
while (drtopics.Read())
{
ChapterNames qbsubchapter = new ChapterNames();
qbsubchapter.Qbc_id = (int)drtopics["qbc_id"];
qbsubchapter.Qbc_nameofChapter = drtopics["qbc_nameofChapter"].ToString();
qbsubchapter.Qbc_no_of_papers = (int)drtopics["qbc_no_of_papers"];
qbsubchapter.Qbc_no_of_questions = (int)drtopics["qbc_no_of_questions"];
chptrsdetails.Add(qbsubchapter);
}
drtopics.Close();
cn.Close();
string topic_username = cmd.Parameters["#username"].Value.ToString();
string topic_password = cmd.Parameters["#password"].Value.ToString();
string topic_package_name = cmd.Parameters["#package_name"].Value.ToString();
bool result = check_user(topic_username, topic_password, topic_package_name);
if (result == true)
return chptrsdetails;
else
return null;
}
catch (SqlException ex)
{
return null;
}
finally
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
}
}
}
}
public bool check_user(string topic_username, string topic_password, string topic_package_name)
{
string requestedUrl = OperationContext.Current.IncomingMessageHeaders.To.AbsoluteUri;
if (WebOperationContext.Current != null)
{
if (WebOperationContext.Current.IncomingRequest != null)
{
if (WebOperationContext.Current.IncomingRequest.Headers["username"] != null && WebOperationContext.Current.IncomingRequest.Headers["password"] != null && WebOperationContext.Current.IncomingRequest.Headers["packagename"] != null)
{
string username = WebOperationContext.Current.IncomingRequest.Headers["username"];
string pwd = WebOperationContext.Current.IncomingRequest.Headers["password"];
string pckgname = WebOperationContext.Current.IncomingRequest.Headers["packagename"];
bool result = Base64Decode(username, pwd, pckgname, topic_username, topic_password, topic_package_name);
if (result == true)
return true;
else
return false;
}
}
}
return false;
}
For html encoding (you don't specify other), use the static method
HttpUtility.HtmlEncode(string)
http://www.dotnetperls.com/httputility

facebook graph api version "2.4 "could not access email,gender information in the "me" tag

my sample project at registered at developer.facebook version 2.4 and requested permissions are *
email,birthday,gender
*
default.aspx
string code = Request.QueryString["code"];
if (!string.IsNullOrEmpty(code))
{
// dynamic info = fb.Get("me?birthday");
string data = FaceBookConnect.Fetch(code, "me");
FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
faceBookUser.PictureUrl = string.Format("https://graph.facebook.com/{0}/picture", faceBookUser.Id);
pnlFaceBookUser.Visible = true;
lblId.Text = faceBookUser.Id;
lblUserName.Text = faceBookUser.UserName;
lblName.Text = faceBookUser.Name;
lblEmail.Text = faceBookUser.Email;
lblbirthday.Text = faceBookUser.birthday;
lblf_name.Text =faceBookUser.first_name;
lblgender.Text = faceBookUser.gender;
ProfileImage.ImageUrl = faceBookUser.PictureUrl;
btnLogin.Enabled = false;
}

How to call a function with struct as input?

Here is my struct definition, function and the portion calling the function.
public struct NewSigningRequest
{
public string SerialNumber;
//public string Requestor;
public string Sponsor;
public string Approver;
public string BusinessJustification;
public byte[] DebugFile;
public string DebugFileName;
public string FirmwareVersion;
public string FirmwareDescription;
public byte[] SmokeTestResult;
public string ProductName;
public string SigningType;
}
static public bool CreateSigningRequest(NewSigningRequest Request)
{
Request = new NewSigningRequest();
bool succeeded = false;
string sqlcmdString = sqlQueryNewSigningRequest;
SqlConnection con = new SqlConnection(connection);
SqlCommand Insertcmd = new SqlCommand(sqlcmdString, con);
SqlParameter SerialNumber = new SqlParameter("#SerialNumber", SqlDbType.NVarChar, 50);
SerialNumber.Value = Request.SerialNumber;
Insertcmd.Parameters.Add(SerialNumber);
SqlParameter Requestor = new SqlParameter("#Requestor", SqlDbType.NVarChar, 20);
Requestor.Value = GetRequestor.GetRequestorAlias();
Insertcmd.Parameters.Add(Requestor);
SqlParameter Sponsor = new SqlParameter("#Sponsor", SqlDbType.NVarChar, 20);
Sponsor.Value = Request.Sponsor;
Insertcmd.Parameters.Add(Sponsor);
SqlParameter BusinessJustification = new SqlParameter("#BusinessJustification", SqlDbType.NVarChar, 2000);
BusinessJustification.Value = Request.BusinessJustification;
Insertcmd.Parameters.Add(BusinessJustification);
SqlParameter DebugFile = new SqlParameter("#DebugFile", SqlDbType.VarBinary, 8000);
DebugFile.Value = Request.DebugFile;
Insertcmd.Parameters.Add(DebugFile);
SqlParameter DebugFileName = new SqlParameter("#DebugFileName", SqlDbType.NVarChar, 100);
DebugFileName.Value = Request.DebugFileName;
Insertcmd.Parameters.Add(DebugFileName);
SqlParameter ProductName = new SqlParameter("#ProductName", SqlDbType.NVarChar, 20);
ProductName.Value = Request.ProductName;
Insertcmd.Parameters.Add(ProductName);
SqlParameter SigningType = new SqlParameter("#SigningType", SqlDbType.NVarChar, 10);
SigningType.Value = Request.SigningType;
Insertcmd.Parameters.Add(SigningType);
SqlParameter FirmwareVersion = new SqlParameter("#FirmwareVersion", SqlDbType.NVarChar, 50);
FirmwareVersion.Value = Request.FirmwareVersion;
Insertcmd.Parameters.Add(FirmwareVersion);
SqlParameter FirmwareDescription = new SqlParameter("#FirmwareDescription", SqlDbType.NVarChar, 250);
FirmwareDescription.Value = Request.FirmwareDescription;
Insertcmd.Parameters.Add(FirmwareDescription);
SqlParameter SmokeTestResult = new SqlParameter("#SmokeTestResult", SqlDbType.VarBinary, 8000);
SmokeTestResult.Value = Request.SmokeTestResult;
Insertcmd.Parameters.Add(SmokeTestResult);
return succeeded;
}
this is how I am trying to call it
NewSigningRequest Request;
byte[] bin;
string FileName;
if (FileUpload.HasFile)
{
bin = new byte[FileUpload.PostedFile.ContentLength];
HttpPostedFile mybin = FileUpload.PostedFile;
FileName = mybin.FileName;
mybin.InputStream.Read(bin, 0, FileUpload.PostedFile.ContentLength);
}
else
{
bin = null;
FileName = "";
}
string NameAlias = #HttpContext.Current.User.Identity.Name;
int index = NameAlias.IndexOf("\\") + 1;
string sAlias = NameAlias.Substring(index);
byte[] SmokeTest;
if (FileUploadSTR.HasFile)
{
SmokeTest = new byte[FileUploadSTR.PostedFile.ContentLength];
HttpPostedFile mySmokeTest = FileUploadSTR.PostedFile;
mySmokeTest.InputStream.Read(SmokeTest, 0, FileUploadSTR.PostedFile.ContentLength);
}
else
{
SmokeTest = null;
}
Request.SerialNumber = TextBoxSerialNumber.Text;
Request.Sponsor = TextBoxSponsor.Text;
Request.BusinessJustification = TextBoxBJ.Text;
if (bin == null)
{
Request.DebugFile = new byte[0];
}
else
{
Request.DebugFile = bin;
}
Request.DebugFileName = FileName;
Request.FirmwareVersion = TextBoxFV.Text;
Request.FirmwareDescription = TextBoxFD.Text;
if (TextBoxSigningType.Text == string.Empty)
{
Request.SigningType = drp2.SelectedValue.ToString();
}
else
{
Request.SigningType = TextBoxSigningType.Text.ToUpper();
}
if (SmokeTest == null)
{
Request.SmokeTestResult = new byte[0];
}
else
{
Request.SmokeTestResult = SmokeTest;
}
SurfaceSignDBAccess.CreateSigningRequest(Request);
upon calling this function, gives error saying that "use of unassigned local variable 'Request'."
What should be the right way to call this function?
NewSigningRequest Request; - is never initialized in the method, before calling
SurfaceSignDBAccess.CreateSigningRequest(Request);
try this:
var request = new NewSigningRequest();// in the first line of code of the second code snippet.
And in the static method, remove the following code.
Request = new NewSigningRequest();

Stored procedure executing but not able to access data in asp.net

I have a stored procedure that executes perfectly in SQL Server. However I am not able to access the rows that are return by it in asp.net from Data Access Layer
My DataAccessLayer code is as follows:
public List<AdvancePaymentRep> getPaymentAdvanceData(int? InternalCompany = 0, string Currency = "", DateTime? InvoiceDateFrom = null, DateTime? InvoiceDateTo = null, DateTime? AdvDateDueFrom = null, DateTime? AdvDateDueTo = null)
{
CreateConnectionString();
List<AdvancePaymentRep> paymentAdvanceCollection = new List<AdvancePaymentRep>();
SqlDataReader rdrval = null;
SqlCommand command1 = sqlConnection.CreateCommand();
command1.CommandType = System.Data.CommandType.StoredProcedure;
command1.CommandText = "[dbo].[NST_GetDataForAdvancePaymentReport]";
if (InternalCompany != 0)
{
SqlParameter parametersInternalCompany = new SqlParameter();
parametersInternalCompany.ParameterName = "#AlhInternalCie";
parametersInternalCompany.SqlDbType = System.Data.SqlDbType.Int;
parametersInternalCompany.Direction = ParameterDirection.Input;
parametersInternalCompany.Value = InternalCompany;
command1.Parameters.Add(parametersInternalCompany);
}
SqlParameter parametersCurrency = new SqlParameter();
parametersCurrency.ParameterName = "#AlhCurrency";
parametersCurrency.SqlDbType = System.Data.SqlDbType.NVarChar;
parametersCurrency.Direction = ParameterDirection.Input;
parametersCurrency.Value = Currency;
command1.Parameters.Add(parametersCurrency);
if (InvoiceDateFrom != Convert.ToDateTime("01/01/0001 00:00:00"))
{
SqlParameter parametersInvoiceDateFrom = new SqlParameter();
parametersInvoiceDateFrom.ParameterName = "#AldDtCreatedFrom";
parametersInvoiceDateFrom.SqlDbType = System.Data.SqlDbType.Date;
parametersInvoiceDateFrom.Direction = ParameterDirection.Input;
parametersInvoiceDateFrom.Value = InvoiceDateFrom;
command1.Parameters.Add(parametersInvoiceDateFrom);
}
if (InvoiceDateTo != Convert.ToDateTime("01/01/0001 00:00:00"))
{
SqlParameter parametersInvoiceDateTo = new SqlParameter();
parametersInvoiceDateTo.ParameterName = "#AldDtCreatedTo";
parametersInvoiceDateTo.SqlDbType = System.Data.SqlDbType.Date;
parametersInvoiceDateTo.Direction = ParameterDirection.Input;
parametersInvoiceDateTo.Value = InvoiceDateTo;
command1.Parameters.Add(parametersInvoiceDateTo);
}
if (AdvDateDueFrom != Convert.ToDateTime("01/01/0001 00:00:00"))
{
SqlParameter parametersInvoiceDateDueFrom = new SqlParameter();
parametersInvoiceDateDueFrom.ParameterName = "#InvhDtDueFrom";
parametersInvoiceDateDueFrom.SqlDbType = System.Data.SqlDbType.Date;
parametersInvoiceDateDueFrom.Direction = ParameterDirection.Input;
parametersInvoiceDateDueFrom.Value = AdvDateDueFrom;
command1.Parameters.Add(parametersInvoiceDateDueFrom);
}
if (AdvDateDueTo != Convert.ToDateTime("01/01/0001 00:00:00"))
{
SqlParameter parametersInvoiceDateDueTo = new SqlParameter();
parametersInvoiceDateDueTo.ParameterName = "#InvhDtDueTo";
parametersInvoiceDateDueTo.SqlDbType = System.Data.SqlDbType.Date;
parametersInvoiceDateDueTo.Direction = ParameterDirection.Input;
parametersInvoiceDateDueTo.Value = AdvDateDueTo;
command1.Parameters.Add(parametersInvoiceDateDueTo);
}
try
{
if (sqlConnection == null)
{
sqlConnection.Open();
}
rdrval = command1.ExecuteReader(); // Getting HasRows = false out here
EDIT : Have solved the issue there was some problem with how i had supplied the
The last command in your SP should be a SELECT command. Else, you get other results such as the number of rows affected and such. Management Studio is still able to display rows created from one of the SELECTs in your SP but actually they are not the first "thing" that is returned when you call an ADO.NET command against that SP.
After your
rdrval = command1.ExecuteReader();
You'll need to do something like
while (rdrval.Read())
{
//do something
}

Resources