Jump to content

amirag

Members
  • Posts

    5
  • Joined

  • Last visited

amirag's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. amirag

    Add new record

    thank you jesh 4 replying:)good notice... I 'll try itthe problem is solved.. thanx sooo much jesh:)
  2. amirag

    Add new record

    Hi every body I wrote this code which adds new record in the database, it adds perfectly... but the problem here, it adds the row twice in the table. I don't konw why I think there's something wrong in the sequence of the code <!-- #Include File="header.aspx" --><%@ Page Language="vb" Debug="true" %><%@ import Namespace="system.data.oleDb"%><script runat="server">Sub UploadButton_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Loadif session("adminId")<>"" then If IsPostBack Then '/////////dim dbconn,dbcomm,sql,noAdded,strtitle,strdetails,strdate,fileupdbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.MapPath("/db/pscchc_db.mdb"))dbconn.open()strtitle=title.textstrdetails=details.textstrdate=ndate.textfileup=Server.MapPath("/UploadedImages/")& FileUpload1.FileNamesql="insert into news(title,details,ndate,img) VALUES ('" & strtitle & "','" & strdetails & "','" & strdate & "','" & fileup & "');"'create the command objectdbcomm= New OleDbCommand(sql,dbconn)'execute SQL commandnoAdded=dbcomm.executeNonQuery()msg.text="<br><br><font color=red>" & noAdded & "</font> rocord(s) has been Added"'////////////UPLOAD FILE///////////////////// Dim path As String = Server.MapPath("/UploadedImages/") Dim fileOK As Boolean = False If FileUpload1.HasFile Then Dim fileExtension As String fileExtension = System.IO.Path. _ GetExtension(FileUpload1.FileName).ToLower() Dim allowedExtensions As String() = _ {".jpg", ".jpeg", ".gif"} For i As Integer = 0 To allowedExtensions.Length - 1 If fileExtension = allowedExtensions(i) Then fileOK = True End If Next If fileOK Then Try FileUpload1.PostedFile.SaveAs(path & _ FileUpload1.FileName) Label1.Text = "File uploaded!" Catch ex As Exception Label1.Text = "File could not be uploaded." End Try Else Label1.Text = "Cannot accept files of this type." End If End If End IfElseresponse.redirect("main_log.aspx")End if ' close If sessionEnd Sub</script><form runat="server"><table> <tr><td><b>Date: </b></td><td><asp:TextBox ID="ndate" CssClass="input-box" runat="server"></asp:TextBox></td></tr><tr><td><b>Title:</b></td><td><asp:TextBox ID="title" CssClass="input-box" runat="server" Width="200"> </asp:TextBox></td><tr><td valign="top"><b>Details:</b></td><td><asp:TextBox ID="details" TextMode="MultiLine" Width="500" Rows="20" runat="server"></asp:TextBox></td></tr><tr><td><b>Image: </b></td><td> </td></tr><Tr><td colspan="2" align="center"></td></Tr><tr><td colspan="2"><font color="#999999" size="2">Note: maximum image Dimensions are Width:347 * height:260<br></font><asp:FileUpload id="FileUpload1" runat="server"> </asp:FileUpload> <asp:Label ID="Label1" runat="server"></asp:Label></td></tr><tr><td colspan=2><asp:Label ID="msg" runat="server"></asp:Label></td></tr><tr><td colspan="2"><asp:Button Text="ADD" runat="server" CssClass="ButtonFormat2" OnClick="UploadButton_Click"></asp:Button></td></tr></table></form><!-- #Include File="footer.aspx" --> Any suggestion will be welcomeThanx in advance
×
×
  • Create New...