Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Monday, March 26, 2012

Multiple Inserts

Hi, I'm trying to create a form where new names can be added to a database. The webform looks like this:
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
Name:<asp:TextBox ID="newName" runat="server" />
<INPUT id="NewUserBtn" type="button" value="Create New User" name="NewUserBtn" runat="server"
onServerClick="NewBtn_Click">
</form>
And the code behind looks like this:
Public Sub NewBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewUserBtn.ServerClick
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New SqlConnection("server=databaseserver;database=db;uid=uid;pwd=pwd")
MyCommand = New SqlDataAdapter("insert into certifications (name) values ('" & newName.Text & "'); select * from certifications", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Titles")

Response.Redirect("WebForm1.aspx", True)
End Sub
When I try to insert one name it works. When I try to insert a second name, it overwrites the old one. Why is that?
Thanks.
James

(1) Always MASK your connection string when posting on public forums like these. DO NOT post your userid/pwd.
(2) You could do this in a better way by using a stored proc with @.name as an input parameter.
CREATE PROC usp_InsertName ( @.name VARCHAR(100) )
AS
BEGIN
SET NOCOUNT ON
INSERT INTO Certifications
VALUES (@.name)
SELECT
<col1>, <col2>...
FROM
Cerfications
SET NOCOUNT OFF
END

(3) Its a bad programming practice to say "SELECT * FROM..". Always explicitly write out your column names.
(4) Currently you are hardcoding the variable names. Your SQL Server is susceptible for SQL Injection Attacks (google for more info). You should use Parameterized queries to prevent this.|||Thanks for the tips. I'll take care of the select statement and look into using parameterized queries. My problem is that when I run the insert statement, it overwrites the values in there with just the information that is being submitted instead of creating a new row. What I would like is to be able to load the page with any number of entries and just enter a new row and not enter them all at once. Thanks.
James|||If you use the stored proc like I posted above it would work.

Friday, March 23, 2012

multiple image uploads......

I've got a form and little script to upload a image which works fine.

<form......>
<input type=file name=file size=30>
</form>

$updir = "/home/myserver/public_html/casa/images";
@.copy($file, "$updir/$file_name") or die("The file you are trying to upload couldn't be copied to the server");

But when I change the form to upload multiple files and change the script to loop throught the array $file[] I get the 'or die' message "The file you are trying to upload couldn't be copied to the server"

<form......>
<input type=file name=file[] size=30>
<input type=file name=file[] size=30>
</form>

$file_count = count($file);
$i = 1;
while($i <= $file_count ){
$updir = "/home/myserver/public_html/casa/images";
@.copy($file, "$updir/$file_name") or die("The file you are trying to upload couldn't be copied to the server");
$i++
}

Any body see what I'm doing wronge here?

Thanks in advanceworked it out...

for ($i=0;$file[$i];$i++){
$updir = "/home/thinkdes/public_html/casa/images/property";
@.copy($file[$i], "$updir/$file_name[$i]") or die("The file $file_name[$i] couldn't be copied to the server");
}|||Can you post the full working code?

Multiple Image Load

How can I upload several pictures at once to use in a SQL Report? There are
over 6,000 pictures that I need available for a form letter that will include
a picture of the product referenced in the letter.
If I can load all of them at once into the project and reference them by
name connected from a stored procedure to the name of the picture, that would
be fine.
Someone on another board it was suggested I store the source in a SQL
database, but it hasn't worked when I try it that way.> Someone on another board it was suggested I store the source in a SQL
> database, but it hasn't worked when I try it that way.
Do you mean the you are storing OLE images in a SQL Database - and if you
view them say with Microsoft Access from the SQL table - you can see the
image ok, but when you try to put these images in a Reporting Services
Report you can't see them ?
If this is the case then you need to strip the first 105 chars from the
image to remove the OLE Header when trying to view the image in Reporting
Services.
We deal with this on pages 364 - 365 in the "Hitchhiker's Guide to SQL
Server 2000 Reporting Services"
What I would say though is that you may be better off hosting the images on
an IIS server and referencing the URL in the database, rather than storing
image blob data in a SQL Server 2000 database.
Peter Blackburn
Hitchhiker's Guide to SQL Server 2000 Reporting Services
http://www.sqlreportingservices.net
"UNOTech" <UNOTech@.discussions.microsoft.com> wrote in message
news:3482251C-7006-4A22-81C0-404CA456476B@.microsoft.com...
> How can I upload several pictures at once to use in a SQL Report? There
> are
> over 6,000 pictures that I need available for a form letter that will
> include
> a picture of the product referenced in the letter.
> If I can load all of them at once into the project and reference them by
> name connected from a stored procedure to the name of the picture, that
> would
> be fine.
> Someone on another board it was suggested I store the source in a SQL
> database, but it hasn't worked when I try it that way.

Multiple Forms

I have multiple page form that may differ each time they are call. Each may also be mutilple page long. Having trouble trying to print page 1 then swithcing to new form and print it......ect. Any Help would be wonderful. Crystal support don't unserstand my problem.

Thanks In Advance

HenryMe neither, can u please describe ur problem little bit more.|||Let me try one more once.

I have to print an Invoice Form

It has three diferent formats in other words each page has a diff Vb Form

Sometimes we must repeat the same looking form other times we want to switch to another form.

This seem to be such a simple problem have done this kind of thing for years but Crystal Reporter just isn't very willing to do what I want.

I am willing to fax said forms to anyone willing to help.

I feel sure there must be other people out there that would love to be able to do what I have described.

Thanks in advance

Henrysql

Monday, February 20, 2012

Multiple Attachments

How do I get multiple attachments into one mail note. I have five reports
that I what my uses to receive in the form of Excel and PDF attachments and I
do not want them to get five Emails. Is this possible with subscriptions
Thanks
DougYou need to set up a master report that contains the other reports as sub
reports. This is fairly easy to do. The master report can be blank or can
have links to jump to particular sub reports. Note that if you have headers
and footers in your sub reports you might need to tweek them a little to get
it to look just the way you want. Also, you might need to spend a little
effort to make sure that page breaks happen in the right spots if you are
exporting to a format like PDF.
"dlong" wrote:
> How do I get multiple attachments into one mail note. I have five reports
> that I what my uses to receive in the form of Excel and PDF attachments and I
> do not want them to get five Emails. Is this possible with subscriptions
> Thanks
> Doug
>