I want to display news inside the marquee markup in my banking application but its not happening.Please somebody help me what is the error in my code.Here is my code:
<marquee bgcolor="silver" direction="left" id="marq1" runat="server" behavior="scroll" scrolldelay="80" style="height: 19px" width="565">
<%
String se = Session["countnews"].ToString();
for (int i = 0; i < int.Parse("" +se); i++)
{ %>
<strong><%Response.Write(" " + Session["news"+i] + " "); %></strong>
<% } %>
</marquee>
public class News
{
DataSet ds = new DataSet("Bank");
SqlConnection conn;
String check;
SqlDataAdapter sda;
int i;
public string News_Name;
public int Count_News;
public int newsticker()
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BankingTransaction"].ConnectionString.ToString());
check = "Select NewsTitle from News where NewsStatus = 'A'";
sda = new SqlDataAdapter(check, conn);
sda.Fill(ds, "News");
if (ds.Tables[0].Rows.Count > 0)
{
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
News_Name =i+ ds.Tables[0].Rows[i].ItemArray[0].ToString();
}
Count_News = ds.Tables[0].Rows.Count; }
else
{
News_Name =0+ "Welcome to WestSide Bank Online Web site!";
Count_News = 1;
}
return int.Parse(Count_News.ToString());
}
protected void Page_Load(object sender, EventArgs e)
{
News obj = new News();
try
{
obj.newsticker();
Session["news"] = obj.News_Name.ToString();
Session["countnews"] = obj.Count_News.ToString();
}
catch (SqlException ex)
{
Response.Write("Error in login" + ex.Message);
Response.Redirect("Default.aspx");
}
finally
{
obj = null;
}
}
Session["news"+i]
But you're not putting anything called ‘news’-plus-an-integer into Session scope. You're iterating over a dataset and storing each title (mysteriously prefixed by an integer) as the ‘News_Name’ property in a single News object. Each write to ‘News_Name’ overwrites the previous one, so only the last title gets stored at the end in Session["news"].
In any case, Session is a troublesome place to be storing per-page data: Session is for data that persists over multiple page loads, and can interfere if the user is loading two pages at once.
Also, you're Response.Write()ing a string without HTMLEncode()ing it on the way out, which is bad news for security (especially on a ‘banking site’!) if the title of the news might have a ‘<’ character in it. And I'm not quite sure why you're taking the ‘newscount’ integer, converting it to string, converting it to string again, converting it to string again then finally parsing it back to an integer. (?)
In general this seems like an uncomfortable mix of classic-ASP and codebehind techniques. It seems to me it should be possible to write this a whole lot simpler using something like:
<asp:Repeater DataSourceID="TickerSource" runat="server">
<ItemTemplate><strong>
<%# Eval("NewsTitle") %>
</strong></ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="TickerSource" runat="server"
SelectCommand="SELECT NewsTitle FROM News WHERE NewsStatus='A'"
ConnectionString="<%$ ConnectionStrings:BankingTransaction %>"
/>
[Disclaimer: I've never actually written a line of ASP.NET in my life, so this may not work as-is. Edits from more .NET-savvy users welcome.]
Related
I am trying to get the values of data from four different columns of an SQL table to display in my list-box so that the format is "value1, value2, value3, value4". I have my SQL connection control set up with two joins that I have tested in SSMS and pulls the current data. So far I can only get one column of data to display at a time, and I am wondering what the best method would be to display all four values separated by commas.my screenshot:
I have tried making variables to attach each value with a .SelectedValue, but this did not alter the appearance of the list-box whatsoever.
First, always paste in your code (a screen shot means I can't grab your code - and it not pracital to re-type or test your code "as is".
However, the main issue/problem with a listbox is they really only are designed to display one column (and a hidden database row PK used for selecting the options).
As a result, it makes more sense to use a different control since listbox only displays ONE column from the database.
So, I could fill a listbox with hotel names, allow multiple selections and have the code spit out a list of "pk id" for the selecting.
So, say this markup:
<h2>Select Hotels</h2>
<asp:ListBox ID="ListBox1" runat="server"
DataValueField="ID"
DataTextField="HotelName" Width="192px" Height="180px"
SelectionMode="Multiple" >
</asp:ListBox>
<br />
<br />
<asp:Button ID="cmdShowSel" runat="server"
Text="Show Selections" CssClass="btn" OnClick="cmdShowSel_Click" />
Note VERY close in above, the 2 setting for the listbox (datavalue = hidden database PK value, and DataTextField = display column).
so, while I am feeding the listbox many columns, it can only display one column (text), and also return the hidden database PK value of id (value).
So, code behind can be this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
LoadData();
}
void LoadData()
{
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4))
{
string strSQL =
"SELECT ID, HotelName FROM tblHotelsA ORDER BY HotelName";
using (SqlCommand cmdSQL = new SqlCommand(strSQL, conn))
{
conn.Open();
DataTable rstData = new DataTable();
rstData.Load(cmdSQL.ExecuteReader());
ListBox1.DataSource = rstData;
ListBox1.DataBind();
}
}
}
protected void cmdShowSel_Click(object sender, EventArgs e)
{
foreach (ListItem OneRow in ListBox1.Items)
{
if (OneRow.Selected)
{
Debug.Print($"Database PK = {OneRow.Value} Text = {OneRow.Text}");
}
}
}
So, we run this
hold down ctrl-key and click for multiple selectons.
And now when I click the button, I get this output to the debug/immediate window:
output:
Database PK = 16 Text = Batman's Cave
Database PK = 5 Text = Inns of Banff
Database PK = 6 Text = Swiss Village
However, if we want multiple columns, then better to use a listview, or even perahps a grid view.
Lets use a gridview.
So, now this markup:
And code behind, much the same, but we use a select *, and get all columns from the database.
So, this code:
void LoadData()
{
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4))
{
string strSQL =
"SELECT * FROM tblHotelsA ORDER BY HotelName";
using (SqlCommand cmdSQL = new SqlCommand(strSQL, conn))
{
conn.Open();
DataTable rstData = new DataTable();
rstData.Load(cmdSQL.ExecuteReader());
GridView1.DataSource = rstData;
GridView1.DataBind();
}
}
}
<h2>Select Hotels</h2>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" CssClass="table" Width="40%">
<Columns>
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="HotelName" HeaderText="HotelName" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="Select " ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkSel" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And we now see/get this:
So, as you can see, the above allows multiple columns were as a listbox does not.
The UI is also nice, since the user does not have use ctrl-click (that can be tricky for new users).
So, now our button click code is this:
protected void cmdShowSel_Click(object sender, EventArgs e)
{
foreach (GridViewRow OneRow in GridView1.Rows)
{
CheckBox chkMySel = (CheckBox)OneRow.FindControl("chkSel");
if (chkMySel.Checked)
{
int PK = (int)GridView1.DataKeys[OneRow.RowIndex]["ID"];
string s =
$"row index click {OneRow.RowIndex} " +
$"Data base PK = {PK} " +
$"Hotel name = {OneRow.Cells[1].Text}";
Debug.Print(s);
}
}
}
output:
row index click 1 Data base PK = 5 Hotel name = Inns of Banff
row index click 7 Data base PK = 6 Hotel name = Swiss Village
So, a listbox is the wrong choice of a control for displaying multiple columns of data.
My code look like below.
protected void btnApprove_Click(object sender, EventArgs e)
{
if (id == "Button2")
{
string sql = #"update AdjTranSeqDetails set Approver1Status = 'Rejected',finalStatus='Rejected' ,updatedtime = GETDATE(),Approver1Comment ='{1}',modifieduser = '{2}' where TranSeq ={0}";
sql = String.Format(sql, tbxTranSeq.Text, TextBox2.Text, Master.CurrentUser);
string sql2 = #"INSERT INTO AdjTranSeqDetailsHistory SELECT * FROM AdjTranSeqDetails WHERE tranSeq={0}";
sql2 = String.Format(sql2, tbxTranSeq.Text);
string sql3 = #"delete from AdjTranSeqDetails where tranSeq={0}";
sql3 = String.Format(sql3, tbxTranSeq.Text);
if (dba.SqlUpdate(sql, ref ex, ref rowCt) || dba.SqlInsert(sql2, ref ex, ref rowCt) ||dba.SqlDelete(sql3, ref ex, ref rowCt))
{
string sscript = "<script language=\"Jscript\" > ";
if (Master.PageMode == "View")
{
sscript += "if (window.opener && !window.opener.closed) ";
sscript += "{window.opener.DoSearch();}";
}
sscript += "window.opener='x';self.close();";
sscript += "</Script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "SelfClose", sscript);
}
}
updateapp();
GetBillTranInfo();
}
Like Button2, like have 10 button. If one if condition function done I need to close the window and need to reload the page. Can I do like this?
I have tried like above but that is not working for me.
In my user controls, after updating data I do:
Response.Redirect(Request.RawUrl);
That ensures that the page is reloaded, and it works fine from a user control. You use RawURL and not Request.Url.AbsoluteUri to preserve any GET parameters that may be included in the request.
You probably don't want to use: __doPostBack, since many aspx pages behave differently when doing a postback.
The Download command is showing in front of all the rows, I want to show it to only those rows having PDF file attached in the database.
protected void gvupdationsummary_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(st);
con.Open();
SqlCommand com = new SqlCommand("select [name],[data] from [Pragati].[dbo].[Pragati_Status_Updations] where Pragati_no=#Pragati_no", con);
com.Parameters.AddWithValue("Pragati_no", gvupdationsummary.SelectedRow.Cells[3].Text);
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.Buffer = true;
//Response.ContentType = dr["type"].ToString();
Response.AddHeader("content-disposition", "attachment;filename=" + dr["name"].ToString());
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite((byte[])dr["data"]);
Response.End();
}
else
{
// ...
}
}
The code that you show seems to do the actual PDF download already. There is nothing you can do there to prevent the showing of a download button or link.
Instead you need to change the SQL query that provides data for gvupdationsummary, and add a column such as HasPDF there, like this:
SELECT /* your columns */ ,
CAST(CASE WHEN [data] IS NULL THEN 0 ELSE 1 END AS BIT) AS HasPDF
FROM ....
WHERE ....
Then in your grid rendering code you can use the boolean value of HasPDF to decide if the Download button should be shown.
Using this approach you don't needlessly transfer all PDF binary data from your database to your application, every time the grid is being rendered.
You can use SQLDataReader's IsDBNull method to see whether the column contains non-existent or missing values.
ind idx = dr.GetOrdinal("data");
if (!dr.IsDBNull(idx))
{
// set download link on to response.
}
else
{
}
I am using a C# class.Everythink working fine but i am facing this error, so please help to fix this error.
public void Filldropdownlist(DropDownList ddl, string DisplayVal, string Qstr)
{
try
{
CreateConn();
SqlCommand cmd = new SqlCommand(Qstr, constr);
SqlDataReader reader = cmd.ExecuteReader();
ddl.Items.Clear();
ddl.Items.Add(new ListItem(DisplayVal, "none"));
while (reader.Read())
{
ddl.Items.Add(new ListItem(reader(0).ToString(), reader(1).ToString()));
ddl.DataTextField = reader(0).ToString();
ddl.DataValueField = reader(1).ToString();
}
}
catch (Exception ex)
{
}
finally
{
CloseConn();
}
}
problem coming in inside the while loop.
Indexing in C# is done with the [] operator, not with the () operator as in, for example Visual Basic.
In essence
reader(0)
means "call the method reader with and argument 0" and
reader[0]
means give me value with the index 0 within the variable reader.
Aside from that, the DataTextField and the DataValueField are used only if you are data-binding the drop down, not if you are manually inserting the items, so those two lines can be omitted.
They are also incorect, because they need to be set to the name of the fields, not to their values
Change like this:
while (reader.Read())
{
ddl.Items.Add(new ListItem(reader[0].ToString(), reader(1).ToString()));
ddl.DataTextField = reader[0].ToString();
ddl.DataValueField = reader[1].ToString();
}
use [] instead of ()
I am trying to "insert" (or) "add a row" to Purchase Requisition using standard BAPI (PurchaseRequisition.CreateFromData).
I am using JCo3. The example in JCo3 indicates that we should use table.appendRow() OR table.insertRow() methods. I am trying with table.appendRow() & table.appendRows(1). When i try to insert a row, i dont get any error and the row is not inserted.
Below is the program i am trying to execute.
/** Below are the inputs required for this program to run /
/ Step 1 **/
String BAPI_NAME = "BAPI_REQUISITION_CREATE";
/** Step 2 **/
String query_input_column1 = "DOCUMENTY_TYPE";
String query_input_column1_value = "NB";
String query_input_column2 = "PREQ_NAME";
String query_input_column2_value = "Name";
String query_input_column3 = "ACCTASSCAT";
String query_input_column3_value = "U";
String query_input_column4 = "DELIV_DATE";
String query_input_column4_value = "20131101";
String query_input_column5 = "MATERIAL";
String query_input_column5_value = "DELL-RQ2013";
String query_input_column6 = "QUANITY";
int query_input_column6_value = 10100;
/** Step 3 **/
String targetTableUnderBAPI = "REQUISITION_ITEMS";
/** Step 4 **/
/** For the confirmation read the value from export parameter after insertion execution **/
String result_column1 = "NUMBER";
JCoDestination destination = null;
try {
destination = JCoDestinationManager.getDestination(DestinationManager.DESTINATION_NAME1);
JCoRepository repository = destination.getRepository();
JCoContext.begin(destination);
JCoFunction function = repository.getFunction(BAPI_NAME);
if(function == null)
throw new RuntimeException(BAPI_NAME + " not found in SAP.");
System.out.println("BAPI Name from function object: " + function.getName());
//function.getImportParameterList().setValue(query_input_column1, query_input_column1_value);
JCoTable table = function.getTableParameterList().getTable(targetTableUnderBAPI); //it is taken from the response value of metadata
//System.out.println("No of Columns: "+ table.getNumColumns());
System.out.println("Trying to execute append row");
table.appendRow();
table.setValue(query_input_column1,query_input_column1_value);
table.setValue(query_input_column2,query_input_column2_value);
table.setValue(query_input_column3,query_input_column3_value);
//table.setValue(query_input_column4,new java.util.Date(query_input_column4_value));
//skipped Other columns related code
try{
function.execute(destination);
}
catch(AbapException e){
System.out.println(e.toString());
return;
}
System.out.println("Let us check the result from export parameter");
String exportParamStructure = (String)function.getExportParameterList().getValue(result_column1); //getStructure(result_column1); // getValue(result_column1);
System.out.println("Resulting PR#: "+exportParamStructure);
} catch (JCoException e) {
e.printStackTrace();
}
finally
{
try {
JCoContext.end(destination);
} catch (JCoException e) {
e.printStackTrace();
}
}
I did not understand how to read the response and am trying to fetch it from exportParameters!!
Can anybody share a piece of code to insert and
getting confirmation response (do we get the PREQ_NO in response?)
I am adding date field value as "20131101", but not sure if the format and approach is right?
when i try to add Quantity column value, i get an error message complaining this column is not part of BAPIEBANC. But the column is visible in BAPIEBANC type.
any configuration on SAP side to be checked?
should i activate any fields in JCo side? if so, how
Please note that my knowledge on SAP is very limited.
Waiting for an expert's response.
Thanks.
First, you should take a look at SAP JCo documentation, e.g.
http://help.sap.com/saphelp_nw04/helpdata/en/6f/1bd5c6a85b11d6b28500508b5d5211/content.htm
Regarding your code:
Adding (one) row to the table looks right on first sight.
Your code says QUANITY instead of QUANTITY.
You should add date values as java.util.Date; if creating a Date from a String format, you should use java.text.DateFormat.parse(). See http://docs.oracle.com/javase/6/docs/api/java/util/Date.html (this is however Java specific and has nothing to do with JCo).
If changing anything in SAP, never forget to call BAPI_TRANSACTION_COMMIT in the end to finish the logical unit of work (aka transaction) or nothing will actually be changed.
If you don't like to fiddle with the more or less complicated and verbose JCo API, try using Hibersap which gives you a much nicer programming model when calling functions in SAP ERP: http://hibersap.org.
However, you will still need a basic understanding on how SAP function modules work technically (such as parameter types or data types) as well as on the domain specific model which lies behind them (in your case, creating a requisition). I.e. you may need to communicate with your SAP experts.
Here I added 2 types of insertion :
insertval() function for user defined module resides in sap with the help of abap programmer
Its an standard module for insert a ticket using jco to SOLMAN system. First you have to analyse import, export, table & structure parameters, and according to that you have to pass values and retrieve response. In second function it will return ticket n° after successfull insertion of ticket in solman.
I hope this sample code will help you, it worked for me.
public class jco
{
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "192.1.1.1");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "01");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "500");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "uname");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "pwd");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDestinationDataFile(DESTINATION_NAME1, connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDestinationDataFile(DESTINATION_NAME2, connectProperties);
System.err.println("hai");
}
static void createDestinationDataFile(String destinationName, Properties connectProperties)
{
File destCfg = new File(destinationName+".jcoDestination");
try
{
try (FileOutputStream fos = new FileOutputStream(destCfg, false)) {
connectProperties.store(fos, "for tests only !");
}
}
catch (IOException e)
{
throw new RuntimeException("Unable to create the destination files", e);
}
}
public void insertval() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME1);
JCoFunction jf=destination.getRepository().getFunction("ZUSER_DET");
jf.getImportParameterList().setValue("FIRST_NAME","member");
jf.getImportParameterList().setValue("LAST_NAME","c");
jf.getImportParameterList().setValue("USER_NO","1000");
jf.execute(destination);
System.out.println(jf);
}
public void insertticket() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
System.out.println("test"+"\n");
JCoFunction jf=destination.getRepository().getFunction("BAPI_NOTIFICATION_CREATE");
JCoTable jt1=jf.getTableParameterList().getTable("APPX_HEADERS");
JCoTable jt2=jf.getTableParameterList().getTable("APPX_LINES");
JCoTable jt3=jf.getTableParameterList().getTable("APPX_LINES_BIN");
JCoTable jt4=jf.getTableParameterList().getTable("NOTIF_NOTES");
JCoTable jt5=jf.getTableParameterList().getTable("NOTIF_PARTNERS");
JCoTable jt6=jf.getTableParameterList().getTable("NOTIF_SAP_DATA");
JCoTable jt7=jf.getTableParameterList().getTable("NOTIF_TEXT_HEADERS");
JCoTable jt8=jf.getTableParameterList().getTable("NOTIF_TEXT_LINES");
JCoStructure jfn1=jf.getImportParameterList().getStructure("NOTIF_EXT");
JCoStructure jfn2=jf.getImportParameterList().getStructure("NOTIF_CRM");
JCoStructure jfn3=jf.getImportParameterList().getStructure("IBASE_DATA");
jfn1.setValue("NUMB","1234");
jfn1.setValue("REFNUM","123");
jfn1.setValue("TYPE_NOTIF","SLFN");
jfn1.setValue("SUBJECT","tl");
jfn1.setValue("PRIORITY","2");
jfn1.setValue("LANGUAGE","EN");
jfn1.setValue("CATEGORY","Z01");
jfn2.setValue("CODE","0011");
jfn2.setValue("CODEGROUP","0011");
jfn2.setValue("CATEGORY","Z01");
jfn3.setValue("INSTANCE","489");
jfn3.setValue("IBASE","500");
jt1.appendRow();
jt1.setValue("DESCR","practise");
jt2.appendRow();
jt2.setValue("LINE","CVXCVXCV");
jt3.appendRow();
jt3.setValue("LINE","second text line");
jt4.appendRow();
jt4.setValue("TYPE_NOTE","my");
jt4.setValue("IDENT","hoe twwrtgw");
jt4.setValue("DESCRIPTION","its description ");
jt5.appendRow();
jt5.setValue("PARNR","new ");
jt5.setValue("TYPE_PAR","FN");
jt5.setValue("FUNC_PAR","EN");
jt5.setValue("PAR_ACTIVE","1");
jt6.appendRow();
jt6.setValue("INSTN","0020214076");
jt6.setValue("COMP","FI-AA");
jt6.setValue("SYSTYPE","P");
jt6.setValue("SYSID","PRD");
jt6.setValue("MANDT","900");
jt8.appendRow();
jt8.setValue("TXT_NUM","1");
jt8.setValue("TDFORMAT",">X");
jt8.setValue("TDLINE","/(performing all test)");
jf.execute(destination);
String jfex=jf.getExportParameterList().getString("REFNUM");
System.out.println("hi "+jfex);
}