472,364 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 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 1494
(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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.