Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Tuesday, March 27, 2012

Binding a SqlDataSource to a TextBox or label

I have a SQL database with 1 column in it.. it is a do not call registry for my office. I want to make a web application so our leads can go on the web and request to be put on the do not call list. problem is, if their number already exists, it gets a violation of primary key...

Normal handling for this would be to do a select query based on user input, and if it exists in the database, tell them that, else do the insert query...

Problem is, i cant seem to figure out how to bind the result of the select query to a textbox or label so i can compare the results to do that logic. Any ideas? This is in asp .net 2.0. Thanks!

-Dan

You can't directly bind to a Label or a TextBox, but you certainly can set the result of your DataSource to the Text property of your control. Here's an example:

ASPX

ProductName = <asp:label id="lblProductName" runat="server" /><asp:objectdatasource id="odsProducts" runat="server" selectmethod="GetProductByProductID"typename="NorthwindTableAdapters.ProductsTableAdapter"><selectparameters><asp:parameter defaultvalue="1" name="ProductID" type="Int32" /></selectparameters></asp:objectdatasource>

CODE-BEHIND

protected void Page_Load(object sender, EventArgs e){if (!this.IsPostBack){DataView dv = (DataView)odsProducts.Select();lblProductName.Text = dv[0]["ProductName"].ToString();}}

|||

Acctually... i figured out a way... check this out..

Dim dv As Data.DataView = SqlDataSource1.Select(DataSourceSelectArguments.Empty)

TextBox1.Text = dv.ToTable.Rows(0)("PHONE")

This works, but now i have another problem. If there is no row 0 (meaning if the number doesnt exist) the page fails. How can i check to see if the record doesnt exist, then do something else?

|||Just check to see if the DataView.Count property is greater than 0.|||Thanks, that worked great!

Thursday, March 22, 2012

Binary files in DB : set name on retrieve

Hello,

I have a table that stores binary files. When I serve them up to the user, I call the following page (serveDocument.aspx?DocumentID=xxx) which holds only the following code and pass the document ID:

Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load
Dim DocumentIDAs Integer = Convert.ToInt32(Request.QueryString("DocumentID"))

'Connect to the database and bring back the image contents & MIME type for the specified picture Using myConnectionAs New SqlConnection(ConfigurationManager.ConnectionStrings("kelly_lmConnectionString1").ConnectionString)

Const SQLAs String ="SELECT [Content_Type], [Document_Data] FROM [lm_Service_Detail_Documents] WHERE [Document_id] = @.Document_id"Dim myCommandAs New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@.Document_id", DocumentID)

myConnection.Open()
Dim myReaderAs SqlDataReader = myCommand.ExecuteReader

If myReader.ReadThen Response.ContentType = myReader("Content_Type").ToString()
Response.BinaryWrite(myReader("Document_Data"))
End If myReader.Close() myConnection.Close()End Using
End Sub

It works perfectly. But heres the thing: I want users to be able to right click on the link and chose 'Save Target As'. In IE 7, this works fine. In FireFox it saves the document as 'serveDocument.aspx'. Is there any way toinjectthe filename that I want to save the document as?

Thank you.

Add this Header also

context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename+".txt" + "\"");

------------------

Mark as Answer if you feel

|||

What does 'context' refer to?

And, are you saying I shouldn't set the ContentType to the actual type of file?


|||

REmove the context

it uses to html encode when you are using http handler

|||

Well, that partially works. When a user clicks the linkthen saves the file, the correct name is present. But, my issue isn't that... I want the user to be able to right click the link and 'Save Link As...' with the correct filename. When I do that, it still says 'documentServe.aspx'.

|||

Hi,

But heres the thing: I want users to be able to right click on the link and chose 'Save Target As'. In IE 7, this works fine. In FireFox it saves the document as 'serveDocument.aspx'.

From your description, it seems that when you right click on the link and choose the 'save target as' in IE7, you can got the whole url with parameters, but not in FireFox, right?

If so, I'm afraid that the behavior is related to the Explorer, and based on my knowledge, there's not any workaround to fix the problem, since working mechanism for IE and FireFox is just not the same.

Thanks.

sql

Tuesday, March 20, 2012

Big Picture Advice please to a SQL 2000 intermediate/beginner user

I am migrating a Mid-Frame DB to SQL Server 2000 PC.
I will call oldDB, OldTables the ones that belong to the Mid-Frame.
I will call newDB, newTables the ones that belong to the PC.
The oldDB has many versions and I have retrieved the oldTables to CSV
Files and then I use DTS to make a oldTables as tempTables in SQL 2000
PC.
I need to transform data and process the columns in tempTables to
create the NewTables (ie Final Tables).
I have used SQL scripts with UDFs to accomplish one run for one
version of OldDB to newDB.
The question is : Should I use ADO.NET or embedded SQL to process the
TemPTables
And CSV Files or Should stick with SQL SELECT, INSERT, UPDATE scripts
to do this ?
I have used SQL scripts with a dozen UDFs, is it time to start using
other tools /objects like SPs ?
GigaThanksInAdvanceGiga,
IMHO, if it works for you the way you're doing it, then I reckon stick with
it until you're comfortable moving to other features of SQL like stored
procs.
ADO.NET or SQL to me makes no diff if the end result is the same. You might
find things process quicker with native SQL commands. And there's not much
difference between scripts which run your UDFs or SPs to run them. Scripts
you run in QA will give you more of a visual on what's going on.
cheers
Danny
<placidite1@.yahoo.com> wrote in message
news:1179264486.895840.101790@.n59g2000hsh.googlegroups.com...
>I am migrating a Mid-Frame DB to SQL Server 2000 PC.
> I will call oldDB, OldTables the ones that belong to the Mid-Frame.
> I will call newDB, newTables the ones that belong to the PC.
> The oldDB has many versions and I have retrieved the oldTables to CSV
> Files and then I use DTS to make a oldTables as tempTables in SQL 2000
> PC.
> I need to transform data and process the columns in tempTables to
> create the NewTables (ie Final Tables).
> I have used SQL scripts with UDFs to accomplish one run for one
> version of OldDB to newDB.
> The question is : Should I use ADO.NET or embedded SQL to process the
> TemPTables
> And CSV Files or Should stick with SQL SELECT, INSERT, UPDATE scripts
> to do this ?
> I have used SQL scripts with a dozen UDFs, is it time to start using
> other tools /objects like SPs ?
>
> GigaThanksInAdvance
>

Big Picture Advice please to a SQL 2000 intermediate/beginner user

I am migrating a Mid-Frame DB to SQL Server 2000 PC.
I will call oldDB, OldTables the ones that belong to the Mid-Frame.
I will call newDB, newTables the ones that belong to the PC.
The oldDB has many versions and I have retrieved the oldTables to CSV
Files and then I use DTS to make a oldTables as tempTables in SQL 2000
PC.
I need to transform data and process the columns in tempTables to
create the NewTables (ie Final Tables).
I have used SQL scripts with UDFs to accomplish one run for one
version of OldDB to newDB.
The question is : Should I use ADO.NET or embedded SQL to process the
TemPTables
And CSV Files or Should stick with SQL SELECT, INSERT, UPDATE scripts
to do this ?
I have used SQL scripts with a dozen UDFs, is it time to start using
other tools /objects like SPs ?
GigaThanksInAdvanceGiga,
IMHO, if it works for you the way you're doing it, then I reckon stick with
it until you're comfortable moving to other features of SQL like stored
procs.
ADO.NET or SQL to me makes no diff if the end result is the same. You might
find things process quicker with native SQL commands. And there's not much
difference between scripts which run your UDFs or SPs to run them. Scripts
you run in QA will give you more of a visual on what's going on.
cheers
Danny
<placidite1@.yahoo.com> wrote in message
news:1179264486.895840.101790@.n59g2000hsh.googlegroups.com...
>I am migrating a Mid-Frame DB to SQL Server 2000 PC.
> I will call oldDB, OldTables the ones that belong to the Mid-Frame.
> I will call newDB, newTables the ones that belong to the PC.
> The oldDB has many versions and I have retrieved the oldTables to CSV
> Files and then I use DTS to make a oldTables as tempTables in SQL 2000
> PC.
> I need to transform data and process the columns in tempTables to
> create the NewTables (ie Final Tables).
> I have used SQL scripts with UDFs to accomplish one run for one
> version of OldDB to newDB.
> The question is : Should I use ADO.NET or embedded SQL to process the
> TemPTables
> And CSV Files or Should stick with SQL SELECT, INSERT, UPDATE scripts
> to do this ?
> I have used SQL scripts with a dozen UDFs, is it time to start using
> other tools /objects like SPs ?
>
> GigaThanksInAdvance
>