Advertisement
ChloeRed

sql

Mar 15th, 2013
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. <%@ Page Language="VB" %>
  2.  
  3. <%@ Import Namespace="System.Data.SqlClient" %>
  4. <%@ Import Namespace="System.Data" %>
  5. <%@ Import Namespace="System.Net" %>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7.  
  8. <script type="text/javascript" language="javascript">
  9. function YouSure()
  10. {
  11. return confirm("This will add this article onto the News page (www.site.co.uk/news) immediately\nAre you sure you want to do this?","title")
  12. }
  13. </script>
  14.  
  15. <script runat="server">
  16.  
  17. Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  18. 'If MsgBox("This will add this article onto the News page (www.site.co.uk/news) immediately" & _
  19. ' vbCrLf & "Are you sure you want to do this?", MsgBoxStyle.YesNo + MsgBoxStyle.Question + MsgBoxStyle.DefaultButton2, "Submit News Article?") = MsgBoxResult.Yes Then
  20. Call foo()
  21. 'Else
  22. ' 'Cancelled
  23. ' MsgBox("This News Article will not be added to the system", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Operation Cancelled")
  24. 'End If
  25. End Sub
  26.  
  27. Sub foo()
  28.  
  29. Dim strTitle as String=contitle.Text
  30. dim strContent as String=concontent.Text
  31. dim dtDate as Date=format(Today(), "yyyy-MM-dd")
  32.  
  33. Dim strConn As String = "Data Source=DEDICAT-NJSHC7G\SQLEXPRESS;Initial Catalog=listrweb;UID=user;PWD=pass"
  34.  
  35. Dim MyConn As New SqlConnection(strConn)
  36.  
  37. Dim MySQL As String = "INSERT INTO tblNews (Page, News, DateItem, Active) values ('" & _
  38. Replace(strTitle, "'", "") & "', '" & Replace(strContent, "'", "") & "', '" & format(Today(), "yyyy-MM-dd") & "', 'Yes')"
  39. Dim Cmd As New SqlCommand(MySQL, MyConn)
  40.  
  41. MyConn.Open()
  42. Try
  43. Cmd.ExecuteNonQuery()
  44. Catch ex As Exception
  45. Server.Transfer("news_problem.aspx")
  46. Exit Sub
  47. End Try
  48. MyConn.Close()
  49.  
  50. Server.Transfer("news_worked.aspx")
  51.  
  52. End Sub
  53.  
  54. Private Sub getErrorMessage(ByVal theReasonForTheError As String)
  55. MsgBox("Your error message is: " & vbNewLine & theReasonForTheError, MsgBoxStyle.Critical)
  56. End Sub
  57. </script>
  58.  
  59. <html xmlns="http://www.w3.org/1999/xhtml" >
  60. <head>
  61. <title>List Recruitment :: Add News Page</title>
  62. <link rel="stylesheet" type="text/css" title="BP Colour Scheme" href="css/menu.css" />
  63. <link rel="stylesheet" type="text/css" title="BP Colour Scheme" href="css/table.css" />
  64. <script language="VB" runat="server" type="text/VB">
  65. Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
  66. 'Check if there is an active session
  67. If Len(Session.Item("fname")) = 0 Then
  68. 'No active session - get the user to log in first
  69. Response.Redirect("login.aspx")
  70. 'Else
  71. 'There is an active session - ie user has logged in.
  72. 'label2.Text = "<strong>Hello " & Session("fname") & ", welcome to the BP Ops Support Online Job Tracking System.<br />Click Active Tasks to get started!</strong><br /><br /><strong>Please note:</strong> If you close the browser window, or leave the screen unattended for 20 minutes, you will need to log back in."
  73. End If
  74.  
  75. End Sub
  76. </script>
  77. </head>
  78. <body style="background-image:none; font-family: Arial; position: static; text-align: left;">
  79. <table border="0" style="width: 100%">
  80. <tr>
  81. <td rowspan="2" style="width: 155px">
  82. </td>
  83. <td align="right" colspan="2" rowspan="2">
  84. <a href="http://www.site.co.uk" id="Back to main website" target="_blank"><img alt="Back to main site Website" src="img/list_rec.jpg" border="0"/></a></td>
  85. </tr>
  86. </table>
  87.  
  88. <div class="menutabs">
  89. <ul>
  90. <li><a href="#">Job Listing Administration</a></li>
  91. </ul>
  92. </div>
  93.  
  94. <span class="BPHeading"><br />Add News Article<br /></span>
  95.  
  96. <form id="form1" runat="server">
  97. <div class="table">
  98. <ul>
  99. <li class="even"><asp:Label ID="newsTitle" runat="server" Font-Bold="True" Text="Article Title"></asp:Label></li>
  100. <li class="odd"><asp:Label ID="newsContent" runat="server" Font-Bold="True" Text="Article Content"></asp:Label></li>
  101. </ul>
  102. <ul>
  103. <li class="even"><asp:TextBox ID="conTitle" runat="server" Width="500px"></asp:TextBox></li>
  104. <li class="odd"><asp:TextBox ID="conContent" runat="server" Height="192px" Width="500px" TextMode="MultiLine"></asp:TextBox></li>
  105. </ul>
  106. </div>
  107.  
  108. <div>
  109. &nbsp;<asp:Button ID="Submit" runat="server" OnClientClick="return YouSure();" OnClick="Submit_Click" Text="Submit" Width="81px" />
  110. </div>
  111.  
  112. </form>
  113.  
  114. </body>
  115.  
  116. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement