473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Conflicting results with identical code

I am having conflicting results with two pieces of identical code. One
is an insert, the other is an update to a db.

The first code, which works, is this:

Sub Add3_Click(sender As Object, e As EventArgs)
Dim imgStream as Stream = Add3Image.PostedFile.InputStream
Dim imgLen as Integer = Add3Image.PostedFile.ContentLength
Dim imgType as String = Add3Image.PostedFile.ContentType
If Not imgStream Is Nothing And imgLen > 0 And (imgType =
"image/jpeg" Or imgType = "image/pjpeg") Then
Dim imgBin() as Byte
imgBin = createThumbnail(imgStream, 200, 200)
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("INSERT INTO tblNews ([Date], [Name],
[Image], [Comment]) VALUES (@Date, @Name, @Image, @Comment)", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
request.form("Add3Date")
myCmd.Parameters.Add("@Name", OleDbType.VarWChar).Value =
RepChar(request.form("Add3Title"))
myCmd.Parameters.Add("@Image", OleDbType.LongVarBinary).Value = imgBin
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
RepChar(request.form("Add3Comment"))
myCmd.ExecuteNonQuery()
myConn.Close()
Else
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("INSERT INTO tblNews ([Date], [Name],
[Comment]) VALUES (@Date, @Name, @Comment)", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
request.form("Add3Date")
myCmd.Parameters.Add("@Name", OleDbType.VarWChar).Value =
RepChar(request.form("Add3Title"))
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
RepChar(request.form("Add3Comment"))
myCmd.ExecuteNonQuery()
myConn.Close()
End If
Server.Transfer(request.form("Add3Reload"))
End Sub

<h3>Add News</h3>
<table border="0" cellspacing="2" caption="Layout Table for adding data
into the database">
<tr><td class="right">Date:</td><td><input type="text" id="Add3Date"
style="display: none;" runat="server" /><img src="/images/cal.png"
height="16" width="16" alt="Choose Calendar Date" id="calendar_trigger"
/> <span id="show_date"><%= DateTime.Now.ToString("dddd, dd MMMM, yyyy")
%></span></td></tr>
<tr><td class="right">Title:</td><td><input type="text"
id="Add3Title" maxlength="50" class="required" runat="server" /></td></tr>
<tr><td class="right">Image:</td><td><input type="file"
id="Add3Image" class="required" runat="server" /></td></tr>
<tr><td class="right">News:</td><td><textarea id="Add3Comment"
rows="4" cols="60" class="required" runat="server"></textarea></td></tr>
<tr><input type="hidden" id="Add3Reload" runat="server"
/><td></td><td><asp:Button OnClick="Add3_Click" Text="Add News Article"
runat="server" /></td></tr>
</table>
<script type="text/javascript" src="/js/calendar.js"></script>
<script type="text/javascript" src="/js/calendar-en.js"></script>
<script type="text/javascript" src="/js/calendar-setup.js"></script>
<script language="JavaScript">
Calendar.setup({
inputField : "Add3Date",
ifFormat : "%d/%m/%Y 12:00:00 AM",
displayArea : "show_date",
daFormat : "%A, %d %B, %Y",
button : "calendar_trigger",
align : "br",
singleClick : true
});
</script>

The other code, which DOESN'T work, is this:

Sub Edit3Update(sender As Object, e As EventArgs)
Dim imgStream as Stream = Edit3Image.PostedFile.InputStream
Dim imgLen as Integer = Edit3Image.PostedFile.ContentLength
Dim imgType as String = Edit3Image.PostedFile.ContentType
If Not imgStream Is Nothing And imgLen > 0 And (imgType =
"image/jpeg" Or imgType = "image/pjpeg") Then
Dim imgBin() as Byte
imgBin = createThumbnail(imgStream, 200, 200)
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("UPDATE tblNews SET [Date]=@Date,
[Name]=@Name, [Image]=@Image, [Comment]=@Comment WHERE [ID]=@ID", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
request.form("Edit3Date")
myCmd.Parameters.Add("@Name", OleDbType.VarWChar).Value =
RepChar(request.form("Edit3Title"))
myCmd.Parameters.Add("@Image", OleDbType.LongVarBinary).Value = imgBin
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
RepChar(request.form("Edit3Comment"))
myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
request.form("Edit3ID")
myCmd.ExecuteNonQuery()
myConn.Close()
Else
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("UPDATE tblNews SET [Date]=@Date,
[Name]=@Name, [Comment]=@Comment WHERE [ID]=@ID", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
request.form("Edit3Date")
myCmd.Parameters.Add("@Name", OleDbType.VarWChar).Value =
RepChar(request.form("Edit3Title"))
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
RepChar(request.form("Edit3Comment"))
myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
request.form("Edit3ID")
myCmd.ExecuteNonQuery()
myConn.Close()
End If
' Edit3()
End Sub
<asp:Repeater ID="rptedit3post" runat="server">
<itemtemplate> <p>Preview of This Post:</p>
<blockquote>
<h5><%# Container.DataItem("Name") %></h5>
<%# NewsImage(Ctype(DataBinder.Eval(Container.DataItem ,"ID"), Integer)) %>
<%# FormatDate(Container.DataItem("Date")) %>
<p><%# FormatData(Container.DataItem("Comment")) %></p>
</blockquote>
<p>Use the table below to edit the post. Click on Update to apply any
changes. Click on Delet to delete entire post.</p>
<table border="0" cellspacing="2" caption="Layout Table for adding data
into the database">
<tr><td class="right">Date:</td><td><input type="text" id="Edit3Date"
value='<%# Container.DataItem("Date") %>' style="display: none;"
runat="server" /><img src="/images/cal.png" height="16" width="16"
alt="Choose Calendar Date" id="calendar_trigger" /> <span
id="show_date"><%= DateTime.Now.ToString("dddd, dd MMMM, yyyy")
%></span></td></tr>
<tr><td class="right">Title:</td><td><input type="text"
id="Edit3Title" value='<%# Container.DataItem("Name") %>'
maxlength="50" class="required" runat="server" /></td></tr>
<tr><td class="right">Image:</td><td><input type="file"
id="Edit3Image" runat="server" /></td></tr>
<tr><td class="right">News:</td><td><textarea id="Edit3Comment"
rows="4" cols="60" class="required" runat="server"><%#
Container.DataItem("Comment") %></textarea></td></tr>
<tr><td><input type="hidden" id="Edit3ID" value='<%#
Container.DataItem("ID") %>' runat="server" /></td><td>
<asp:Button OnClick="Edit3Update" Text="Update News Article"
runat="server" /> &nbsp;
<asp:Button OnClick="Edit3Delete" Text="Delete News Article"
runat="server" /></td></tr>
</table>
<script type="text/javascript" src="/js/calendar.js"></script>
<script type="text/javascript" src="/js/calendar-en.js"></script>
<script type="text/javascript" src="/js/calendar-setup.js"></script>
<script language="JavaScript">
Calendar.setup({
inputField : "Edit3Date",
ifFormat : "%d/%m/%Y 12:00:00 AM",
displayArea : "show_date",
daFormat : "%A, %d %B, %Y",
button : "calendar_trigger",
align : "br",
singleClick : true
});
</script>
</itemtemplate>
</asp:Repeater>


The first one works, but the second one doesn't seem to work no matter
WHAT I try to do. As you can see, the code is nearly identical (with the
major exception of the SQL statements).

One major problem with the second one is an "Edit3Image is not defined"
error, even though it exists in the form. When I checked out the form,
however (view source in my browser), I saw that all of the ID tags had
changed dramatically - to the value plus a nonsensical string. Not only
did that ensure that "Edit3Image" couldn't be found, but that also
prevented the JavaScript (a popup calendar) from allowing the date to be
changed in "Edit3Date". How do I make both the JS and the form work
together???

BTW, the second is inside a repeater because I *need* it to be filled
with content from the database. It is the update/delete page, whereas
the first one was the add page.

Fucking frustrated

....Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************
Feb 2 '06 #1
1 1556
(a) too much code, it hurts my eyes
(b) don't use bad language!
(c) I believe the problem to be simple

Edit3Image is defined in a repeater. As such you cannot simply refer to it
as Edit3Image as there are multiple versions (one for each "row" of data
bound to the repeater). How does .NET know which Edit3Image you want to
manipulate/access? If you want it to work in your javascript, you need to do
something like inputField : '<%# Edit3Date.ClientId %>' which I think will
work.

To make it work in your button click, as there are multiple rows, you'll
need to figure out which Edit3Image you want. If you want each one, you need
to loop through the items of the Repeater, if you want a specific one, you
need to jump to that index:

dim Edit3Date as HtmlInput =
ctype(myRepeater.Items[1].FindControl("Edit3Date"), HtmlInput)
Karl

--
http://www.openmymind.net/

"Neo Geshel" <go****@geshel.org> wrote in message
news:bilEf.417301$2k.230941@pd7tw1no...
I am having conflicting results with two pieces of identical code. One is
an insert, the other is an update to a db.

The first code, which works, is this:

Sub Add3_Click(sender As Object, e As EventArgs)
Dim imgStream as Stream = Add3Image.PostedFile.InputStream
Dim imgLen as Integer = Add3Image.PostedFile.ContentLength
Dim imgType as String = Add3Image.PostedFile.ContentType
If Not imgStream Is Nothing And imgLen > 0 And (imgType = "image/jpeg"
Or imgType = "image/pjpeg") Then
Dim imgBin() as Byte
imgBin = createThumbnail(imgStream, 200, 200)
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("INSERT INTO tblNews ([Date], [Name],
[Image], [Comment]) VALUES (@Date, @Name, @Image, @Comment)", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
request.form("Add3Date")
myCmd.Parameters.Add("@Name", OleDbType.VarWChar).Value =
RepChar(request.form("Add3Title"))
myCmd.Parameters.Add("@Image", OleDbType.LongVarBinary).Value = imgBin
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
RepChar(request.form("Add3Comment"))
myCmd.ExecuteNonQuery()
myConn.Close()
Else
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("INSERT INTO tblNews ([Date], [Name],
[Comment]) VALUES (@Date, @Name, @Comment)", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
request.form("Add3Date")
myCmd.Parameters.Add("@Name", OleDbType.VarWChar).Value =
RepChar(request.form("Add3Title"))
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
RepChar(request.form("Add3Comment"))
myCmd.ExecuteNonQuery()
myConn.Close()
End If
Server.Transfer(request.form("Add3Reload"))
End Sub

<h3>Add News</h3>
<table border="0" cellspacing="2" caption="Layout Table for adding data
into the database">
<tr><td class="right">Date:</td><td><input type="text" id="Add3Date"
style="display: none;" runat="server" /><img src="/images/cal.png"
height="16" width="16" alt="Choose Calendar Date" id="calendar_trigger" />
<span id="show_date"><%= DateTime.Now.ToString("dddd, dd MMMM, yyyy")
%></span></td></tr>
<tr><td class="right">Title:</td><td><input type="text" id="Add3Title"
maxlength="50" class="required" runat="server" /></td></tr>
<tr><td class="right">Image:</td><td><input type="file" id="Add3Image"
class="required" runat="server" /></td></tr>
<tr><td class="right">News:</td><td><textarea id="Add3Comment" rows="4"
cols="60" class="required" runat="server"></textarea></td></tr>
<tr><input type="hidden" id="Add3Reload" runat="server"
/><td></td><td><asp:Button OnClick="Add3_Click" Text="Add News Article"
runat="server" /></td></tr>
</table>
<script type="text/javascript" src="/js/calendar.js"></script>
<script type="text/javascript" src="/js/calendar-en.js"></script>
<script type="text/javascript" src="/js/calendar-setup.js"></script>
<script language="JavaScript">
Calendar.setup({
inputField : "Add3Date",
ifFormat : "%d/%m/%Y 12:00:00 AM",
displayArea : "show_date",
daFormat : "%A, %d %B, %Y",
button : "calendar_trigger",
align : "br",
singleClick : true
});
</script>

The other code, which DOESN'T work, is this:

Sub Edit3Update(sender As Object, e As EventArgs)
Dim imgStream as Stream = Edit3Image.PostedFile.InputStream
Dim imgLen as Integer = Edit3Image.PostedFile.ContentLength
Dim imgType as String = Edit3Image.PostedFile.ContentType
If Not imgStream Is Nothing And imgLen > 0 And (imgType = "image/jpeg"
Or imgType = "image/pjpeg") Then
Dim imgBin() as Byte
imgBin = createThumbnail(imgStream, 200, 200)
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("UPDATE tblNews SET [Date]=@Date,
[Name]=@Name, [Image]=@Image, [Comment]=@Comment WHERE [ID]=@ID", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
request.form("Edit3Date")
myCmd.Parameters.Add("@Name", OleDbType.VarWChar).Value =
RepChar(request.form("Edit3Title"))
myCmd.Parameters.Add("@Image", OleDbType.LongVarBinary).Value = imgBin
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
RepChar(request.form("Edit3Comment"))
myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
request.form("Edit3ID")
myCmd.ExecuteNonQuery()
myConn.Close()
Else
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("UPDATE tblNews SET [Date]=@Date,
[Name]=@Name, [Comment]=@Comment WHERE [ID]=@ID", myConn)
myConn.Open()
myCmd.CommandType = CommandType.Text
myCmd.Parameters.Add("@Date", OleDbType.Date).Value =
request.form("Edit3Date")
myCmd.Parameters.Add("@Name", OleDbType.VarWChar).Value =
RepChar(request.form("Edit3Title"))
myCmd.Parameters.Add("@Comment", OleDbType.LongVarWChar).Value =
RepChar(request.form("Edit3Comment"))
myCmd.Parameters.Add("@ID", OleDbType.Integer).Value =
request.form("Edit3ID")
myCmd.ExecuteNonQuery()
myConn.Close()
End If
' Edit3()
End Sub
<asp:Repeater ID="rptedit3post" runat="server">
<itemtemplate> <p>Preview of This Post:</p>
<blockquote>
<h5><%# Container.DataItem("Name") %></h5>
<%# NewsImage(Ctype(DataBinder.Eval(Container.DataItem ,"ID"), Integer)) %>
<%# FormatDate(Container.DataItem("Date")) %>
<p><%# FormatData(Container.DataItem("Comment")) %></p>
</blockquote>
<p>Use the table below to edit the post. Click on Update to apply any
changes. Click on Delet to delete entire post.</p>
<table border="0" cellspacing="2" caption="Layout Table for adding data
into the database">
<tr><td class="right">Date:</td><td><input type="text" id="Edit3Date"
value='<%# Container.DataItem("Date") %>' style="display: none;"
runat="server" /><img src="/images/cal.png" height="16" width="16"
alt="Choose Calendar Date" id="calendar_trigger" /> <span
id="show_date"><%= DateTime.Now.ToString("dddd, dd MMMM, yyyy")
%></span></td></tr>
<tr><td class="right">Title:</td><td><input type="text" id="Edit3Title"
value='<%# Container.DataItem("Name") %>' maxlength="50" class="required"
runat="server" /></td></tr>
<tr><td class="right">Image:</td><td><input type="file" id="Edit3Image"
runat="server" /></td></tr>
<tr><td class="right">News:</td><td><textarea id="Edit3Comment" rows="4"
cols="60" class="required" runat="server"><%#
Container.DataItem("Comment") %></textarea></td></tr>
<tr><td><input type="hidden" id="Edit3ID" value='<%#
Container.DataItem("ID") %>' runat="server" /></td><td>
<asp:Button OnClick="Edit3Update" Text="Update News Article"
runat="server" /> &nbsp;
<asp:Button OnClick="Edit3Delete" Text="Delete News Article"
runat="server" /></td></tr>
</table>
<script type="text/javascript" src="/js/calendar.js"></script>
<script type="text/javascript" src="/js/calendar-en.js"></script>
<script type="text/javascript" src="/js/calendar-setup.js"></script>
<script language="JavaScript">
Calendar.setup({
inputField : "Edit3Date",
ifFormat : "%d/%m/%Y 12:00:00 AM",
displayArea : "show_date",
daFormat : "%A, %d %B, %Y",
button : "calendar_trigger",
align : "br",
singleClick : true
});
</script>
</itemtemplate>
</asp:Repeater>


The first one works, but the second one doesn't seem to work no matter
WHAT I try to do. As you can see, the code is nearly identical (with the
major exception of the SQL statements).

One major problem with the second one is an "Edit3Image is not defined"
error, even though it exists in the form. When I checked out the form,
however (view source in my browser), I saw that all of the ID tags had
changed dramatically - to the value plus a nonsensical string. Not only
did that ensure that "Edit3Image" couldn't be found, but that also
prevented the JavaScript (a popup calendar) from allowing the date to be
changed in "Edit3Date". How do I make both the JS and the form work
together???

BTW, the second is inside a repeater because I *need* it to be filled with
content from the database. It is the update/delete page, whereas the first
one was the add page.

Fucking frustrated

...Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************

Feb 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nikolaj Hansen | last post by:
Hi all, I am writing a CMP layer for a database using XDOCLET. That's ok, the problem is with a finder, and results I simply cannot understand. * @ejb.finder *...
10
by: Minti | last post by:
I tried the following code on Borland C++ complier and Microsoft VC7.0 both seem to give conflicting results void foo(const int& x) { std::cout << "In const foo\n"; } void foo(int& x) ...
2
by: humble04 | last post by:
Hi, I am compiling a collection of C++ code. Most of them are using the new format #include <iostream>. I think all of them because I failed at finding out which header file uses the old format ...
6
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how...
7
by: Thiru | last post by:
I am writing an application that interacts with Oracle and Teradata. In order to create the executable, I need to link various Oracle and Teradata libraries. I found out that when I link the...
1
by: Neo Geshel | last post by:
I am having conflicting results with two pieces of identical code. One is an insert, the other is an update to a db. The first code, which works, is this: Sub Add3_Click(sender As Object, e As...
31
by: louishong | last post by:
3rd time posting this as the first two simply disappeared! Here's the issue: We currently run an Access application in the West Coast for tracking resource centric data. For those located in the...
1
by: helraizer1 | last post by:
Hi folks, I have an image based shoutbox which I am currently implementing emoticons onto. I have a way now for the emoticons to appear where the :D or =) etc. is on the image, but for some reason...
12
by: Michael.Z | last post by:
Anyone who can help: Given a Table.h file I am writing a Table.c file. I keep getting the compile error: previous declaration of Table was here / conflicting types for I think the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.