N
Neo Geshel
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">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">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" />
<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. *
***********************************************************************
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">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">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" />
<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. *
***********************************************************************