Connecting a pdf to a database and passing a specific parameter through a URL
Hi,
I have a product data sheet that I want to personalise with partner logos. I need to pass a parameter from a url string to the form and have it populate a specific spot with the partner logo.
How would I go about doing that. I have LiveCycle Designer 8
Thanks,
Nolan
yea.. looks like a mess true.., cos i was puttin all 2geda in a haste..
this is my midlet code....
TextField uname, upass, uacc;
url ="http://localhost:8080/serv/Ser";
uname = new TextField("Firstname:","",30,TextField.ANY);
form.append(uname);
upass = new TextField("Lastname:","",30,TextField.ANY);
form.append(upass);
uacc = new TextField("Account ID:","",30,TextField.ANY);
form.append(uacc);
void connect( String url ) throws IOException {
HttpConnection http =null;
InputStream iStrm =null;
StringBuffer b = new StringBuffer();
try {
http = (HttpConnection)Connector.open(url);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
http.setRequestProperty("Content-Language", "en-CA");
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
iStrm = http.openDataInputStream();
System.out.println(http.getResponseMessage());
System.out.println(http.getResponseCode());
int ch;
while((ch=iStrm.read()) != -1)
b.append((char) ch);
conn.setString(b.toString());
System.out.println(b.toString());
display.setCurrent(conn);
catch(Exception ex)
System.out.println(ex);
conn.setString(String.valueOf(ex));
ex.printStackTrace();
finally
if(iStrm!=null)
iStrm.close();
if(http !=null)
http.close();
}and this is my servlet code.
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException
try
Class.forName("com.mysql.jdbc.Driver");
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:8080","root","pass");
PreparedStatement stat = con.prepareStatement("Select custaid from customers_old where firstname=? and surname=? and custAID=?");
stat.setString(1,req.getParameter("uname"));
stat.setString(2,req.getParameter("upass"));
stat.setString(3,req.getParameter("uacc"));
Similar Messages
-
Problem when using WEB.SHOW_DOCUMENT and passing in lexical parameter
Hi,
I got a blank page with error "An error has occured while trying to use this document" when I tried to use web.show_document and passing a lexical parameter to 10g report on 10gAS. The URL in the web.show_document is:
http://<srvname>:<portnum>/reports/rwservlet?server=repserver90&report=myrpt.rdf&destype=Cache&desformat=pdf&userid=<usr>/<pw>@<db>&where_clause=where%20product_type%20in%20('REPORT')
If I change the desformat to htmlcss, it is fine to display the report. But doesn't work with desformat=pdf. The pdf file has been generated in the cache. Why can't it display on the screen.
Also I tried to use double quote the value for where_clause. The pdf report showed up. But it ignored the where clause.
Experts please help.
YingI use lexical parameters and they work fine, but I use a parameter list. The code is contained in a form that is called by all forms that wish to run a report. This way you only need the logic for printing in a single form. If you want the form, email me at [email protected]
-
Pass the product ID through the URL from the checkout page to the "receipt - buy" landing page. is it possible?
You can just the module_shoppingcartsummary module and with liquid you can render the items in the cart out.
Developer reference -
CHECK for duplicate inside a cursor and pass a ouptut parameter in sql server 2008
Hi All,
I am inserting a value into a table, Before inserting i am checking that record already exists or not in the target table, If its existsing i am making an entry into errorlog table and set the output parameter to 'errorlog' . This is inside the cursor, as
il be passing multiple values. Next is I have separate query to get the new record which is not in the target table. Using EXCEPT i get the new record and i insert into a main table. after insertion i set output as 'success'.
Here while executing the procedure i pass a duplicate value and a new value. As it is in cursor,first it will insert into errorlog and set output parameter as 'errorlog' .Next it will insert a new record into main table and set output parameter as 'Success'.
So on completion of the execution of the procedure i get output as success.
But i should get as errorlog. I should get success only on no errors in the procedure. How i can i achieve this? Please help me.
Below is my code
IF NOT EXISTS(SELECT Beginmilepost,BeginTrackName,Endmilepost,EndTrackName
FROM SSDB_Segment WHERE BeginMilepost>=@BegMP AND EndMilepost<=@EndMP AND SearchID = @SearchID AND Reference = 'Range')
BEGIN
Declare C_Max1 Cursor FOR
(SELECT Beginmilepost,BeginTrackName,Endmilepost,EndTrackName FROM SSDB_Segment WHERE BeginMilepost = @BegMP AND EndMilepost = @EndMP AND BeginTrackName = @BegtrkName
AND EndTrackName = @EndTrkName AND SearchID = @SearchID)
Open C_Max1
FETCH FROM C_MAX1 INTO @BeginMilepost,@BTrackName,@EndMilepost,@ETrackName
WHILE(@@FETCH_STATUS=0)
BEGIN
IF OBJECT_ID ('tempdb..#temp') IS NOT NULL
BEGIN
DROP TABLE #temp
END--IF
Select BeginLatitude,BeginLongitude,BeginTrackName,BeginMilepost,BeginMilepostPrefix,BeginMilepostSuffix,EndLatitude,EndLongitude,EndTrackName,EndMilepost,TrainType into #temp
FROM
SELECT BeginLatitude= case when @BegLat = 0 THEN NULL ELSE @BegLat end ,BeginLongitude= case when @BegLong=0 THEN NULL ELSE @BEgLong end ,@BTrackName AS BeginTrackName,ROUND(@BeginMilepost ,3) AS BeginMilepost,
BeginMilepostPrefix= CASE WHEN @BegPrefix = 'null' THEN NULL ELSE @BegPrefix END,BeginMilepostSuffix= CASE WHEN @BegSuffix = 'null' THEN NULL ELSE @BegSuffix END,
EndLatitude=case when @EndLat =0 then NULL else @EndLat end,EndLongitude=case when @Endlong = 0 THEN NULL ELSE @Endlong END,@ETrackName AS EndTrackName,ROUND(@EndMilepost ,3) AS EndMilepost,@TrainType AS TrainType
UNION ALL
select BeginLatitude,BeginLongitude,BeginTrackName,ROUND(BeginMilepost,3) AS BeginMilepost,BeginMilepostPrefix,BeginMilepostSuffix, EndLatitude,EndLongitude,EndTrackName,ROUND(EndMilepost,3) AS EndMilepost,TrainType from SSDB_MaximumPermissibleSpeed)data
group by BeginLatitude,BeginLongitude,BeginTrackName,BeginMilepost,EndLatitude,EndLongitude,EndTrackName,EndMilepost,BeginMilepostPrefix,BeginMilepostSuffix,TrainType
having COUNT(*)>1
SET @COUNT= (select count(*) from #temp )
Print @COUNT
IF @COUNT>=1
BEGIN
INSERT INTO ErrorLog_Asset (
ErrorCode,
ErrorMessage,
TableName,
MilepostPrefix,
Milepost
SELECT
'1',
'Already exists at BeginMp '+ CAST(@BeginMilepost as varchar) +',EndMp '+ CAST(@EndMilepost as varchar) +' ,Beginlat
'+CAST(@BegLat as varchar)
+' ,Endlat '+CAST(@EndLat as varchar)+', BeginTrackName '+@BTrackName +' and EndTrackName '+@ETrackName
'MaximumPermissibleSpeed',
CASE WHEN @BegPrefix = 'null' THEN NULL
ELSE @BegPrefix END ,
@BeginMilepost
SET @output = 'Errorlog'
END
IF OBJECT_ID ('tempdb..#Max') IS NOT NULL
BEGIN
DROP TABLE #Max
END--IF
Select BeginLatitude,BeginLongitude,BeginTrackName,BeginMilepost,BeginMilepostPrefix,BeginMilepostSuffix,EndLatitude,EndLongitude,EndTrackName,EndMilepost,TrainType into #Max from
(SELECT BeginLatitude= case when @BegLat = 0 THEN NULL ELSE @BegLat end ,BeginLongitude= case when @BegLong=0 THEN NULL ELSE @BEgLong end ,@BTrackName AS BeginTrackName,ROUND(@BeginMilepost ,3)
AS BeginMilepost,
BeginMilepostPrefix= CASE WHEN @BegPrefix = 'null' THEN NULL ELSE @BegPrefix END,BeginMilepostSuffix= CASE WHEN @BegSuffix = 'null' THEN NULL ELSE @BegSuffix END,
EndLatitude=case when @EndLat =0 then NULL else @EndLat end,EndLongitude=case when @Endlong = 0 THEN NULL ELSE @Endlong END,@ETrackName AS EndTrackName,ROUND(@EndMilepost ,3) AS EndMilepost,@TrainType AS TrainType
except
select BeginLatitude,BeginLongitude,BeginTrackName,ROUND(BeginMilepost,3) AS BeginMilepost,BeginMilepostPrefix,BeginMilepostSuffix, EndLatitude,EndLongitude,EndTrackName,ROUND(EndMilepost,3) AS EndMilepost,TrainType
from SSDB_MaximumPermissibleSpeed)data
Declare C_Max2 Cursor FOR
Select BeginMilepost,BeginTrackName,EndMilepost,EndTrackName from #Max
Open C_Max2
FETCH FROM C_Max2 INTO @BeginMP,@BeginTrackName,@EnMP,@EnTrackName
WHILE(@@FETCH_STATUS=0)
BEGIN
IF (Select COUNT(*) from tbl_Trackname )>=1
BEGIN
IF (@TrainType IN (SELECT TrainType FROM SSDB_TrainType )AND (@Speed <>0) AND @BeginMP IS NOT NULL AND @BeginTrackName IS NOT NULL AND @EnMP IS NOT NULL
AND @Direction IN (SELECT Direction FROM SSDB_Direction) AND @EnTrackName IS NOT NULL )
BEGIN-------------
SET @ID = (Select MAX(MaximumpermissibleSpeedID) from SSDB_MaximumPermissibleSpeed)
IF @COUNT =0
BEGIN
INSERT INTO SSDB_MaximumPermissibleSpeed
BeginMilepostPrefix,
BeginMilepostSuffix,
BeginMilepost,
BeginTrackName,
BeginLatitude,
BeginLongitude,
BeginElevation,
EndMilepostPrefix,
EndMilepostSuffix,
EndMilepost,
EndTrackName,
EndLatitude,
EndLongitude,
EndElevation,
Direction,
Speed,
TrainType,
Description,
InsertUser,
S_ID
SELECT
CASE WHEN @BegPrefix = 'null' THEN NULL
ELSE @BegPrefix END,
CASE WHEN @BegSuffix = 'null' THEN NULL
ELSE @BegSuffix END,
@BeginMP ,
@BeginTrackName ,
case WHEN @BegLat = 0 THEN NULL
ELSE @BegLat END,
CASE WHEN @BegLong=0 THEN NULL
ELSE @BegLong END ,
CASE WHEN @BegEle = 0 THEN NULL
ELSE @BegEle END ,
CASE WHEN @EndPrefix = 'null' THEN NULL
ELSE @EndPrefix END,
CASE WHEN @EndSuffix = 'null' THEN NULL
ELSE @EndSuffix END,
@EnMP ,
@EnTrackName ,
case WHEN @EndLat = 0 THEN NULL
ELSE @EndLat END,
CASE WHEN @EndLong=0 THEN NULL
ELSE @EndLong END ,
CASE WHEN @EndEle = 0 THEN NULL
ELSE @EndEle END ,
@Direction ,
@Speed ,
@TrainType ,
CASE WHEN @Description ='null' THEN NULL
ELSE @Description END ,
@InsertUser ,
@UID
INSERT INTO SSDB_MaxSpeed_History
MSID,
BeginMilepostPrefix,
BeginMilepostSuffix,
BeginMilepost,
BeginTrackName,
BeginLatitude,
BeginLongitude,
BeginElevation,
EndMilepostPrefix,
EndMilepostSuffix,
EndMilepost,
EndTrackName,
EndLatitude,
EndLongitude,
EndElevation,
Direction,
Speed,
TrainType,
Description,
S_ID,
NOTES ,
[Action] ,
InsertUser
SELECT
(Select MaximumPermissibleSpeedID from SSDB_MaximumpermissibleSpeed WHERE MaximumPermissibleSpeedID > @ID),
CASE WHEN @BegPrefix = 'null' THEN NULL
ELSE @BegPrefix END,
CASE WHEN @BegSuffix = 'null' THEN NULL
ELSE @BegSuffix END,
@BeginMP ,
@BeginTrackName ,
case WHEN @BegLat = 0 THEN NULL
ELSE @BegLat END,
CASE WHEN @BegLong=0 THEN NULL
ELSE @BegLong END ,
CASE WHEN @BegEle = 0 THEN NULL
ELSE @BegEle END ,
CASE WHEN @EndPrefix = 'null' THEN NULL
ELSE @EndPrefix END,
CASE WHEN @EndSuffix = 'null' THEN NULL
ELSE @EndSuffix END,
@EnMP ,
@EnTrackName ,
case WHEN @EndLat = 0 THEN NULL
ELSE @EndLat END,
CASE WHEN @EndLong=0 THEN NULL
ELSE @EndLong END ,
CASE WHEN @EndEle = 0 THEN NULL
ELSE @EndEle END ,
@Direction ,
@Speed ,
@TrainType ,
CASE WHEN @Description ='null' THEN NULL
ELSE @Description END ,
@UID,
NULL,
'INSERT',
@InsertUser
set @output='Success'
--IF ((@COUNT >=1) AND (@COUNT =0))
--BEGIN
-- SET @output = 'ErrorLog'
--END
--IF (@COUNT = 0)
-- BEGIN
--SET @output ='Success'
--END
--END
END
END------------------------>
DeepaHi Deepa,
If I understand your question correctly, you would like the @Output parameter to contain the value "Success" only if all rows were successful. As soon as one row was found to be a duplicate, the value of @Output at the end of execution should be "ErrorLog".
Currently, you modify the value of @Output in each iteration of the cursor, so at the end of execution you're left with the last value.
In order to change that to work the way you want it, you need to set the value of @Output in the beginning of execution (before entering the cursor) to "Success", and as soon as there is a duplicate row, you should modify the value to "ErrorLog". This way,
if all rows are successful, the value of @Output will be "Success" at the end of execution. On the other hand, if there is even a single duplicate row, the value of @Output will be "ErrorLog" at the end of execution.
I hope this helps...
Guy Glantser
SQL Server Consultant & Instructor
Madeira - SQL Server Services
http://www.madeirasql.com -
PDF stored in database and to view the PDF when clicking on a link
Is it possible to save a PDF document in the database as a blob column and to retrieve the PDF when clicking on the link
Example
Above method is possible for images
See: http://www.oracle.com/technology/obe/apex/apex31nf/apex31blob.htm.
But can I reach the same for PDF documents?
Thanks in advance for your response.
Kind regards,
IloonHello Andy,
This Upload and Download Files is very useful feature in APEX.
However, is there a way of displaying PDF files first in the report by clicking the corresponding link
in the table?
I mean, is it possible to view PDF files first by clicking the link before deciding to download them?
As we see, this approach is used by most websites and after opening and viewing a PDF file, we can save them.
Thanks.
Shurick.
Edited by: Shurick on Sep 28, 2009 12:51 PM -
How to achieve that: store pdf drawings in database, and show in apex app?
Hi,
We have some many machanical drawings in pdf format, they are 1,000 + , I want to manage those drawings, like put them in a database table, possibly in blob format, and then show them in my apex app as an icon of pdf. then if somebody clicks that icon, the drawings will show in another windows, like many websites did.
How to achieve that in an apex app?
any idea?
I always find that hard to do.Search this forum for uploading documents to database, there are many threads.
You could also check out the 2 day training that ships woth Apex.
Gus -
Hi,
I am not able to resolve the error of
“ORA-12514: TNS:listener does not currently know of service requested in connect descriptor”
Below Link is the indication, related to that error.Hi Surbhi.Gupta,
Thank you for posting in MSND forum.
According to your descriptiom, I suggest you could try the following blog to connect to Oracle from Visual Studio check your issue again.
Reference:
http://blogs.msdn.com/b/kaevans/archive/2009/07/18/connecting-to-oracle-from-visual-studio.aspx
In addition, as you said the error message, I did some research about this error message. So I suggest you could refer then following thread to check your error, maybe you will get some useful message.
http://dba.stackexchange.com/questions/36370/oracle-11g-listener-fails-with-ora-12514-and-ora-12505-errors
However, since this issue is related to the third-party database oracle, so if possible, I suggest you could try to post your issue directly to this Oracle official website:http://www.oracle.com/us/corporate/contact/about-your-account-070507.html
, you will get better support.
Thanks for your understanding.
Best Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to get lookup value for a lookup_type and pass as a parameter in OAF
Hi,
I have requirement wherein I have to enable the "Add Attachment" Button only for a particular deliverable name.
Steps I followed
1) I have extended the corresponding Controller class.
2) Sting str1="XYZ";
3) Getting the attachment table bean and the deliverable name thru Data Mappings as Attachment is the built-in funtionality in OAF.
4)Checking if the deliverable name whether it is equal to str1 or not
Case1: If the deliverable name is not equal to str1 then I am placing the insertallowed as BOOLEAN.FALSE
Case2:If not it will be enabled.
5)The functionality as per the requirement is working fine.
6)Here for str1 I have hardcoded the value initially but I need to take up the value from a lookup created for this value because may be in future if for more than one value the "Add Attachment" Button has to enabled they it will be easy to add in the look up only. No need to change the controller class.
7) So please let me know the steps in getting the value from a lookup and have to pass the lookup values (Here str1--"XYZ","ABC","DEF") into the extended Controller Class.
Thanks in Advance,
Regards,
RamyaRamya,
Here for str1 I have hardcoded the value initially but I need to take up the value from a lookup created for this value because may be in future if for more than one value the "Add Attachment" Button has to enabled they it will be easy to add in the look up only. No need to change the controller class.For this u need to iterate through the lookup values.
Share ur existing Controller Code.
Regards,
Gyan -
STORAGE OF PDF IN A TABLE, AND ALSO WAY TO DISPLAY THROUGH THE REPORT
Hello All,
Kindly help me out if possible,
I have a table, lets say table1.
Kindly guide me that if I want to store a PDF under a column of table1 then how can I store it? What the datatype should I use to store this pdf.
Also Kindly give me the way to display this PDF through Report...
Thank you...
Edited by: 974572 on Dec 3, 2012 2:26 AMPLEASE DO NOT SHOUT (in the title as well).
>
I have a table, lets say table1.
Kindly guide me that if I want to store a PDF under a column of table1 then how can I store it? What the datatype should I use to store this pdf.
>
Store in a BLOB column.
>
Also Kindly give me the way to display this PDF through Report...
>
See < a href="https://forums.oracle.com/forums/search.jspa?threadID=&q=display+pdf&objID=f137&dateRange=thisyear&userID=&numResults=15">this link and check the solutions given.</a> -
Method design question...and passing object as parameter to webserice
I am new to webservice...one design question
i am writing a webservice to check whether a user is valid user or not. The users are categorized as Member, Admin and Professional. For each user type I have to hit different data source to verify.
I can get this user type as parameter. What is the best approach to define the method?
Having one single method �isValidUser � and all the client web service can always call this method and provide user type or should I define method for each type like isValidMember, isValidAdmin ?
One more thing...in future the requirement may change for professional to have more required field in that case the parameter need to have more attribute. But on client side not much change if I have a single isValidUser method...all they have to do is pass additional values
isValidUser(String username, String usertype, String[] userAttributes){
if usertype == member
call member code
else if usertype = professional
call professional code
else if usertype = admin
call admin code
else
throw error
or
isValidMember(String username, String[] userAttributes){
call member code
One last question, can the parameter be passed as object in web service like USER object.First of all, here is my code
CREATE OR REPLACE
TYPE USERCONTEXT AS OBJECT
user_login varchar2,
user_id integer,
CONSTRUCTOR FUNCTION USERCONTEXT (
P_LOGIN IN INTEGER
P_ID_ID IN INTEGER
) RETURN SELF AS RESULT
Either your type wont be compiled or this is not the real code.. -
Some more information:
- I have iPhoto '11 and, in iPhone 4S, iOS 5.1;
- I started having this issue about 2 months ago, but I can't associate it with any changes or updates;
- with iTunes, the behaviour is absolutely normal...No, your iPhone and your iPad should not appear in the finder.
I'm not sure what you mean about downloading photos with iPhoto being double handling, but you can download direct to a folder with Image Capture. Image Capture can also be used to delete photos from the Camera Roll on the iPhone or iPad (preferrably after they are downloaded).
You can remove the photos you synced from your phone with iTunes by syncing again with an empty folder, That will delete all the photos that were previously synced that way, replacing them with the contents of the empty folder (that is, nothing). This will not effect photos takes with the camera on your iPhone. -
In PHP how to pass a recordset value through a url
I have a blog set up with PHP/MySQL with two tables (1 table
for blog entry and 1 table for comments on the blog)
I can display the blog and the comment with a LEFT JOIN
recordset like this---
SELECT golf_blog.blog_ID, DATE_FORMAT(
golf_blog.blog_created, '%b %e, %Y') AS blog_created,
golf_blog.blog_author, golf_blog.blog_subject,
golf_blog.blog_article, blog_comments.comment_article
FROM golf_blog LEFT JOIN blog_comments USING (blog_ID)
ORDER BY golf_blog.blog_created ASC
I have a link in the repeat region of this recordset going to
a page with the comment insert form.
blog_ID is the primary key in the blog table and blog_ID is
the index in the comment table.
How do you pass the blog_ID from the recordset to a text
field in the comment insert form through the link?
Or am i even thinking about this in the right way?I figured it out and got it to work by passing the blog_ID as
a variable on the URL link to the comment insert form page
the link is like this
<a href="golfblog_comment.php?$blog_ID=<?php echo
$row_rs_golfblog['blog_ID']; ?>" >Comment</a>
and on the comment page used this code
<?php $blog_ID = '$blog_ID' ;
$blog_ID = $_GET[$blog_ID]?>
and the value of the insert field is this
<?php echo $blog_ID; ?>
I guess reading David Powers is starting to pay off.
Eureka! -
Passing values in hyperlinks through the URL
I am trying to do the following:
<a href = "linkhandler.jsp?value=lee">
then in linkhandler.jsp I am trying to get that value...i have:
String firstName = request.getParameter("lee");
...but when I print its NULL
What is the proper syntax?
Thanks!I actually figured that out..
Now I have
String theLink = request.getParameter("value");
and theLink has a value of : 'http://cs.dal.ca'
I just want the page to automatically redirect to this page using JSP if possible. -
Powershell use Connection String to query Database and write to Excel
Right now I have a powershell script that uses ODBC to query SQL Server 2008 / 2012 database and write to EXCEL
$excel = New-Object -Com Excel.Application
$excel.Visible = $True
$wb = $Excel.Workbooks.Add()
$ws = $wb.Worksheets.Item(1)
$ws.name = "GUP Download Activity"
$qt = $ws.QueryTables.Add("ODBC;DSN=$DSN;UID=$username;PWD=$password", $ws.Range("A1"), $SQL_Statement)
if ($qt.Refresh()){
$ws.Activate()
$ws.Select()
$excel.Rows.Item(1).HorizontalAlignment = $xlCenter
$excel.Rows.Item(1).VerticalAlignment = $xlTop
$excel.Rows.Item("1:1").Font.Name = "Calibri"
$excel.Rows.Item("1:1").Font.Size = 11
$excel.Rows.Item("1:1").Font.Bold = $true
$filename = "D:\Script\Reports\Status_$a.xlsx"
if (test-path $filename ) { rm $filename }
$wb.SaveAs($filename, $xlOpenXMLWorkbook) #save as an XML Workbook (xslx)
$wb.Saved = $True #flag it as being saved
$wb.Close() #close the document
$Excel.Quit() #and the instance of Excel
$wb = $Null #set all variables that point to Excel objects to null
$ws = $Null #makes sure Excel deflates
$Excel=$Null #let the air out
I would like to use connection string to query the database and write results to EXCEL, i.e.
$SQL_Statement = "SELECT ..."
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=10.10.10.10;Initial Catalog=mydatabase;User Id=$username;Password=$password;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand($SQL_Statement,$conn)
do{
try{
$rdr = $cmd.ExecuteReader()
while ($rdr.read()){
$sql_output += ,@($rdr.GetValue(0), $rdr.GetValue(1))
$transactionComplete = $true
catch{
$transactionComplete = $false
}until ($transactionComplete)
$conn.Close()
How would I read the columns and data for $sql_output into an EXCEL worksheet. Where do I find these tutorials?Hi Q.P.Waverly,
If you mean to export the data in $sql_output to excel document, please try to format the output with psobject:
$sql_output=@()
do{
try{
$rdr = $cmd.ExecuteReader()
while ($rdr.read()){
$sql_output+=New-Object PSObject -Property @{data1 = $rdr.GetValue(0);data2 =$rdr.GetValue(1)}
$transactionComplete = $true
catch{
$transactionComplete = $false
}until ($transactionComplete)
$conn.Close()
Then please try to use the cmdlet "Export-Csv" to export the data to excel like:
$sql_output | Export-Csv d:\data.csv
Or you can export to worksheet like:
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $true
$workbook = $excel.Workbooks.Add()
$sheet = $workbook.ActiveSheet
$counter = 0
$sql_output | ForEach-Object {
$counter++
$sheet.cells.Item($counter,1) = $_.data1$sheet.cells.Item($counter,2) = $_.data2}
Refer to:
PowerShell and Excel: Fast, Safe, and Reliable
If there is anything else regarding this issue, please feel free to post back.
Best Regards,
Anna Wang -
Best practise for creating an application that connects to a SQL Server database
I have created an application that connects to a SQL Server database and views information using a datagrid and performs several updates when a button
is selected.
I have created a SQLcontrol.vb using the following code:
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class SQlControl
'connection 1
Public SQLCon As New SqlConnection With {.ConnectionString
= "Data Source=;Initial Catalog=;Integrated Security=True"}
'connection 2
Public SQLCon1 As New SqlConnection With {.ConnectionString
= "Data Source;Initial Catalog=;Integrated Security=True"}
Public sqlcmd As SqlCommand
Public sqlda As SqlDataAdapter
Public sqldataset As DataSet
Public Function hasconnection() As Boolean
Try
SQLCon.open()
SQLCon.close()
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
Public Sub runquery(query As String)
Try
SQLCon.Open()
sqlcmd = New SqlCommand(query,
SQLCon)
'LOAD
SQL RECORDS FOR DATAGROD
sqlda = New SqlDataAdapter(sqlcmd)
sqldataset = New DataSet
sqlda.Fill(sqldataset)
BH READ DIRECTLY FROM THE DATABASE
'Dim
R As SqlDataReader = sqlcmd.ExecuteReader
'While
R.Read
'MsgBox(R.GetName(0)
& ": " & R(0))
'End
While
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
'will
close connection if still open
If SQLCon.State
= ConnectionState.Open Then
SQLCon.Close()
End If
End Try
End Sub
Public Sub runquery1(query As String)
Try
SQLCon1.Open()
sqlcmd = New SqlCommand(query,
SQLCon1)
'LOAD
SQL RECORDS FOR DATAGROD
sqlda = New SqlDataAdapter(sqlcmd)
sqldataset = New DataSet
sqlda.Fill(sqldataset)
BH READ DIRECTLY FROM THE DATABASE
'Dim
R As SqlDataReader = sqlcmd.ExecuteReader
'While
R.Read
'MsgBox(R.GetName(0)
& ": " & R(0))
'End
While
SQLCon1.Close()
Catch ex As Exception
MsgBox(ex.Message)
'will
close connection if still open
If SQLCon1.State
= ConnectionState.Open Then
SQLCon1.Close()
End If
End Try
End Sub
End Class
A code for one of my button which views displays data grid contains the following code:
Private Sub Button1_Click_1(sender As Object,
e As EventArgs) Handles Button1.Click
If SQL.hasconnection
= True Then
SQL.runquery("select
* from tablea")
If SQL.sqldataset.Tables.Count
> 0 Then
DGVData.DataSource = SQL.sqldataset.Tables(0)
End If
End If
End Sub
I am fairly new to vb.net and have read a few books and followed a few tutorials on youtube, what I would like to know is, are there any disadvantages
to the way I have connected to a SQL database using the SQLControl.vb. A lot of the vb books include data adapter and dataset within the form, I'm not sure if I'm following best practice by have the connection details outside of the form.
My other question is, I have created two connections in the SQLControl and call these connections within the same form using the same data adapter
and dataset. It all works fine but I just wanted to know of any potential issues?
Public SQLCon As New SqlConnection With {.ConnectionString
= "Data Source=;Initial Catalog=;Integrated Security=True"}
'connection 2
Public SQLCon1 As New SqlConnection With {.ConnectionString
= "Data Source;Initial Catalog=;Integrated Security=True"}
ThanksMy other question is, I have created two connections in the SQLControl and call these connections within the same form using the same data adapter and dataset. It all works fine but
I just wanted to know of any potential issues
1) You are not using Sepration of concerns for a solution that is doing data access, like using a DAL.
http://en.wikipedia.org/wiki/Separation_of_concerns
2) You are directly issuing SQL commands at the UI, leading to sql injection attacks.
3) You are not using a UI design pattern, which leads you to tightly couple database activity to the UI.
http://www.codeproject.com/Articles/228214/Understanding-Basics-of-UI-Design-Pattern-MVC-MVP
@System243trd, parameters are important to prevent SQL injection attacks (people will insert SQL commands into the database if you do not perform basic checking of what you are passing to the database). If you write a stored procedure try to make
the variables the correct SQL server data type to avoid problems later of people trying to call it directly. Darnold924 is right, I see no code to prevent against SQL injection attacks. In addition, during development in some instances LocalSQLDB
database system is used and during deployment you usually need to use the production SQL server database. Moreover, Linq-to-SQL is used on Windows Phone 8.1 and it is required for phone development later and so I highly recommend learning
it if you plan on developing windows phone applications.
@System243trd, If you want the code for the windows phone app I think it uses the MVVM model or that might be for universal apps or regular windows phone apps. I have been using the windows phone Silverlight pivot or panorama template (it might
be pieces of both). I've already submitted to the windows phone marketplace and it had to go through certification first. I plan on later making an article on it but I need to first fix one or two simple problems I have with it. Here's a link to
the source code if you later want to look at the source code (in vb.net):
https://jeffsblogcodesamples.codeplex.com/downloads/get/1445836
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - Sherlock Holmes. speak softly and carry a big stick - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog
- http://www.computerprofessions.us
Maybe you are looking for
-
Displaying Description for SAP Table Field in the View
Hi We are working on a HANA implementation Project Where we have a requirement to build View on HR tables. Issue: When i join HR infotypes (tables ) in the view it is getting only Technical names and not descriptions. i have used Semantics option whi
-
Idoc will trigger after purchase order release workflow
Hi Workflow Guru, I have a requirement to configure Purchase Order release workflow. I am configure the same its working fine, but my client requirement is when the purchase order finaly release one IDOC will be trigger and the document will send to
-
Apple TV.2: Time & Date Set Up Errors
Hi, I bought the newest version of the Apple TV in Panama and took it with me to Venezuela. Every time I try to "hook it up", it never adjusts the time and date setting and simply says "Activating" until it goes to sleep. I've had it for a long time
-
Configuration Management of Graphics
We are using FrameMaker 7.2 on a networked pc using windows. Our documents are large (2000 pages) and across the suite of manuals we use between 3000 and 4000 graphics. Can anyone recommend a software solution to managing the configuration. Which gra
-
Webdynpro doesn't start after installation of Sneak Preview SAP NetWeaver
Hi, I have just installed the Sneak Preview SAP NetWeaver 2004. In the sap console I see that all the processes have successfully started. However when I try to open the WebDynpro content administrator via browser at http://<host>:<port>/webdynpro/d