Jump to content

Yahweh

Members
  • Posts

    186
  • Joined

  • Last visited

Everything posted by Yahweh

  1. Yahweh

    Formview Woes

    Basically, I'm allowing users to leave comments on articles. So, I have a simple setup:- A formview for taking user input.- A checkbox on the formview to prevent spam from being posted.- If the checkbox is checked, then the formview inserts a new record.- If the checkbox is unchecked, then the formview cancels the insert, and the user is prompted to try again.Unfortunately, when I cancel the insert, all of the textboxes on the formview are cleared, and the user is forced to reenter their data again. I don't want that behavior, I want the textboxes to retain their viewstate when the insert is canceled, but there doesn't seem to be an easy way to do that.How do I force my formview to maintain its viewstate when an insert fails?Here is my formview: <asp:FormView ID="FormView1" runat="server" DataSourceID="sqlSubmitComment" DefaultMode="Insert"> <InsertItemTemplate> <table width="100%" cellspacing="0" cellpadding="5" border="0"> <tr> <td colspan="2"> Leave a comment: </td> </tr> <tr> <td></td> <td></td> <td rowspan="3" width="40%" align="left" valign="top"> <p> <small>YCodes: <br /></small> </p> </td> </tr> <tr> <td width="10%" align="left" valign="top"> Name: </td> <td width="50%" align="left" valign="top"> <asp:TextBox ID="txtAuthor" runat="server" Text='<%# Bind("author") %>' Width="190px"></asp:TextBox></td> </tr> <tr> <td width="10%" align="left" valign="top"> Comment: <p> <small>(HTML is OFF)</small> </p> </td> <td width="50%" align="left" valign="top"> <asp:TextBox ID="txtComment" runat="server" Height="116px" Text='<%# Bind("comment") %>' TextMode="MultiLine" Width="362px"></asp:TextBox></td> </tr> <tr> <td colspan="2" align="center"> <asp:Panel runat="server" ID="pnlHuman"> <p> Check this box if you're a human: <asp:CheckBox ID="chkHuman" runat="server" /> </p> </asp:Panel> <asp:Button CommandName="Insert" ID="Button1" runat="server" Text="Submit Comment" /> </td> </tr> </table> </InsertItemTemplate> </asp:FormView> <asp:SqlDataSource ID="sqlSubmitComment" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNetConnectionString %>" InsertCommand="Submit_New_Comment" InsertCommandType="StoredProcedure"> <InsertParameters> <asp:QueryStringParameter DefaultValue="0" Name="postID" QueryStringField="id" Type="Int32" /> <asp:CookieParameter CookieName="author" Name="author" Type="String" /> <asp:Parameter Name="comment" Type="String" /> <asp:Parameter Name="IPAddress" Type="String" /> </InsertParameters> </asp:SqlDataSource> Protected Sub sqlSubmitComment_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles sqlSubmitComment.Inserting Dim bTrusted As Boolean 'Checks a "trusted" cookie to see if its value = "true" bTrusted = StringGrabber.Cookie("trusted").Equals("true", StringComparison.OrdinalIgnoreCase) If bTrusted = False Then 'Couldn't find the cookie, or the cookies value was 'wrong, so validating the checkbox instead Dim chkHuman As CheckBox = CType(FormView1.FindControl("chkHuman"), CheckBox) bTrusted = chkHuman.Checked 'adding a cookie Dim myCookie As New HttpCookie("trusted") myCookie.Value = bTrusted.ToString myCookie.Expires = DateTime.Now.AddDays(365) Response.Cookies.Add(myCookie) Dim txtAuthor As TextBox = CType(FormView1.FindControl("txtAuthor"), TextBox) myCookie = New HttpCookie("author") myCookie.Value = txtAuthor.Text myCookie.Expires = DateTime.Now.AddDays(365) Response.Cookies.Add(myCookie) End If e.Cancel = Not bTrusted End Sub
  2. Yahweh

    New to ASP

    Its not a problem with the record, its a problem with permissions: in other words, you don't have write-permissions on your database or on the folder where your database resides.I'm pretty sure you're using an access database, then you need to CHMOD the directory where your database is located to rw-------, and CHMOD the .mdb file to rw-------.If you don't know how to do that, then you have a few options:- If your files are on your local server, open up IIS and navigate to the folder and file where your database is located. Right click and choose "Properties", and change the permissions as needed.- If your files are on a remote server, then use an FTP folder to navigate to the folder and file where your database is located. Your FTP will usually have a button or menu option called CHMOD that will allow you to change the permissions of a file or directory. If you can't CHMOD your files from your FTP, email your host and ask them to allow write permissions on the required folders and files.
  3. Yahweh

    New to ASP

    Its just a casting issue. When you get your variables from the querystring, you're not casting them to a particular datatype, so they are treated as strings. Change this code:QTY = Request.Form("QTY")addTo = Request.Form("addTo")subtractFrom = Request.Form("subtractFrom") To this: QTY = cint(Request.Form("QTY"))addTo = cint(Request.Form("addTo"))subtractFrom = cint(Request.Form("subtractFrom")) The cint function is a conversion function that casts a string as an integer.
  4. Yahweh

    Interesting Question?

    Its possible to store MP3s as binary data in a blob field, but why would you want to? Whats the advantage of keeping the MP3s in a database rather than on disk?
  5. Yahweh

    URL rewriting

    There are a couple of ways to rewrite URLs.The simple way is to into your web.config and insert the following code under <system.web>: <urlMappings enabled="true"> <clear/> <add url="~/monkesy/" mappedUrl="~/articles.aspx?topic=monkeys"/> </urlMappings> Unfortunately, urlMappings provides only static URL rewrites. Inexplicably, it doesn't support dynamic URL rewrites where "~/monkey/page/some_page_here" could redirect a user to "~/articles.asp?topic=monkeys&page=some_page_here".The easiest way to get dynamic URL rewrites is adding a Global.asax page to your root directory. If you're using Visual Studio.Net, the page will be created with some default event handlers like Session_Start, Session_End, Application_Start, Application_End. Add the Application_BeginRequest event like this: Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs) Dim myURL As String = HttpContext.Current.Request.Url.AbsolutePath 'matches urls ending with pattern "/articles/some_topic/" 'optionally matches with pattern "/articles/some_topic/page/some_page/" If Regex.IsMatch(myURL, "articles/.+?/(page/\d+/)?$") Then HttpContext.Current.RewritePath(Regex.Replace(myURL, "articles/(.+?)/(?:page/(\d+)/)$", "articles.aspx?year=$1&page=$2")) End If End Sub You should have a good handle on regular expressions to make full use out of dynamic URL rewriting. Thats a simple method of rewriting, but thit has some limitations.I also recommend using the code available at http://www.urlrewriting.net/en/Default.aspx, its fairly easy to use, allows for dynamic url rewrites, etc. Its a little more powerful and robust than the methods or URL rewriting above, and its easy to include in projects.
  6. Yahweh

    Creating a forum

    A few things I want to know first:- When is your project due?- How long have you had to work on it?- What class are you taking?- Did you show up everyday for class?
  7. Yahweh

    Creating a forum

    I'm pretty sure you'll fail if someone just gave you the code.Its not hard to write a forum. Here's a forum I wrote in ASP in less than 3 days:http://www.fstdt.com/forums/default.aspThe first step is setting up your tables. Minimally, you should have the following tables: Users-----ID (autoincrement primary key)Username (varchar 20)Password (varchar 20)Forums------ID (autoincrement primary key)Title (varchar 20)LastPostID (int, foreign key = Posts.ID)Posts------ID (autoincrement primary key)ID_user (int, foreign key = Users.ID)ID_Forum (int, foreign key = Forums.ID)ID_Thread (int)Subject (varchar 100)Post (text)PostDate (datetime) Create a default page that shows all of your forums.Create a login page that allows users to login, store a cookie (not a session variable) that tracks users userID and password.Create a forum page that shows all of your thread, filter by ID_Thread = 0 and ID_Forum = request("f").Create a thread page that shows all of the posts in a thread, filter by ID_Thread = request("t") or ID_post = request("t").If you know what you're doing, that amount of work should take you an hour at most.
  8. Yahweh

    Schools?

    I began programming as a hobby years and years ago, but I went to a IT community college and earned a two-year degree in Computer Science with specialization in web design. I'll be earning my 4-year degree in Computer Science very shortly.I'm glad I learned everything I did, because I recently got a job as a web designer with a starting salary at $35,000/year. Its a hellz of a lot of money compared to my previous employment, stocking shelves in grocery store for $8/hr.
  9. I don't think theres a function for counting the number of columns returned by a query, but its easy to query multiple databases (especially if they are on the same server), you just have to use their fully qualified names.For example, lets say you have an SQL Server with 2 databases called "dept1" and "dept2", and both databases contain an "accounts" table. The fully qualified names of those tables are "dept1.dbo.Accounts" and "dept2.dbo.Accounts". So you might run a query like this:Select * from dept1.dbo.Accounts a1left join (dept2.dbo.accounts a2 on a1.ID = a2.ID) You should be able to do basically the same thing with PostGres, MySQL, Oracle, etc. so long as you know the fully qualified names of your databases and tables.
  10. Yahweh

    VB.Net or C#?

    Here's a debate that could rival "vi vs emacs" in sheer pointlessness, but is there any reason to prefer the VB.Net syntax over C#, or vice versa?At least for me, I just got a job as a web developer for a banking company that emphasizes heavily on VB.Net, so I'll be using that syntax more often. I usually use VB.Net when I'm writing websites and desktop applications, and I use C# when I'm writing games.I prefer the VB.Net syntax for a few reasons:- Braces are the devil. A "}" can me end if, end loop, end class, end namespace, etc. I don't like having to scroll up to find the matching "{" to find out what kind of code block I'm working in.- I can declare optional parameters in functions and constructors. C#, for whatever reason, doesn't retain support for optional parameters, so you have to write a bunch of overloaded functions that all call each other to get the same effect.- Looping syntax is much more intuitive. When you say "For I = 0 to 5", you unambiguously get the numbers 0 through 5. Its a little more difficult to visualize what you get when you use "for (i = 0; i < 5; i++)" rather than "for (i = 0; i <= 5; i++)".- Case insensitive variable names and functions. Seriously, why would "mycounter" be a completely different variable from "myCounter"?C# does have some syntactical advantages with long lines of code, especially long regexes, because you don't need an underscore to continue to the next line.
  11. I'm preparing to create a website that will make heavy use of gridviews and paging. The tables are fairly large, having 100s of 1000s of records, and the queries can return several 1000s of results.The Gridview doesn't perform any optimizations to a query at all when it pages: it executes a query as is, then trims the results to whatever. That means my query might return 10000 records when I only intend to show 20 or so per page. If I'm going to display 20 records, then my query should never return more than 20 records... but the gridview doesn't know how to do that.Normally, I work with MySQL which has a very friendly paging syntax. However, I'll be working with ASP.Net and SQL Server 2000, and the tables are going to look something like this: Articles---------ID - UniqueidTitle - Varchar(100)Article - TextDate - Datetime Queries will look something like this: Select ID, Title, Article from Articles where ID between 10 and 10000 I want to page that query with a gridview efficiently, with 20 or so records per page. I don't return any records that aren't being displayed on screen. What is the best way to get the results I want?
  12. Yahweh

    web 2.0

    No, its a buzzword used to describe a recent trend of web development defined by massive, decentralized collaborative effort by users to generate site content. Social networking sites like Myspace and Facebook, Wikipedia, Flickr, craigslist, eBay, etc all exist because of massive collaborative user effort.As far as site design goes, most Web 2.0 rely on AJAX to make sites look and feel more like desktop applications, depend on RSS feeds to track content on other sites, etc. A few visual elements like rounded "glassy" edges on dividers, heavy use of gradient colors used as backgrounds, heavy use of dropshadows to a site a more 3-d feel, etc.As an example, one of my sites, FSTDT.com falls under the term "Web 2.0" application. Although the design is extremely simple, all of the content on the site is contributed by users; new content sites in a moderation queue, and users control whether the new content will be published on the site or not; after content is published, users can leave comments; I also have a forum where where users can chat amongst themselves. The site would not exist without 1000s and 1000s of volunteers running it everyday. The site is constantly updated everyday with new content without my direct input at all.
  13. <%dim fnamefname = "header.asp"Server.Execute(fname)'remainder of page content goes here%> Or optionally, dim fnamefname = "some query"Server.Execute("page.asp?q=" & fname) Server.Execute is not the same as an include file. An include basically pastes code from file file into another, then it executes all of that code inline as if it were one piece.Server.Execute doesn't work like that. It literally forces the server the make a new page request, then it copies the page output from that page request into your original page. That means you can't share variables between pages when you use Server.Execute.
  14. First, you should learn SQL. "SORTBY" isn't an SQL function, but "ORDER BY" is.Second, it looks like you're trying to modify an existing piece of software. Good luck on that if you don't know PHP, SQL, or how your software even stores page templates.I'm about 99% sure that you won't have to upload any games into your MySQL database, you probably have to upload them to a special folder on your server. In your admin console, there is probably a page that lets you upload games: it'll be saving games to your website, it will not save the binary data in the database (that would be resource intensive and pointless).To create new pages, you need to create a file on your computer, something like "page.php", and upload it to one of the directories on your website. The page will be blank until you put some code into it. I don't think you should try to do that until you learn PHP first.
  15. I'm not sure why you'd want to sort them like that, but you can do that with a simple subquery. Assuming you have a uniqueID called "ID", you can do this:SELECT navn, prisFROM ComputersWHERE ID in (SELECT TOP 10 ID from Computers ORDER BY pris DESC)ORDER BY newID()
  16. See the FullText entry documentation. Fulltext search ignores words less than 4 letters long, it ignores this list of common words, and it ignores words that occur in 50% of the rows.I don't know what requirements you site has, but you don't actually need to create a seperate table for indexing words. You can put the fulltext index right on the table you're searching. For example, if you're table is set up like this:[Articles]ID Title Article ...--- ----- -------1 Bunnies words2 Kitties more words3 Learning PHP some more4 Programming yet more5 Blogs words again6 MySQL Tutorial once more You can create your index like this: ALTER TABLE articles ADD FULLTEXT(Title, Article) To search your table, use this: Select ID, Title, Article From Articles where Match(Title, Article) AGAINST ('words to search'); You don't need to build a seperate table with words to index, MySQL does it behind the scenes for you.
  17. Yahweh

    SQL Query

    All you need are a few self joins: select RM_0tot5.fldPriorityCode as 'Priority', count(datediff(day,RM_0to5.fldRequestDate,RM_6to10.fldComCanDate)) as 'Closed Calls 0-5' count(datediff(day,RM_6to10.fldRequestDate,RM_6to10.fldComCanDate)) as 'Closed Calls 6-10' count(datediff(day,RM_11ormore.fldRequestDate,RM_11ormore.fldComCanDate)) as 'Closed Calls 11+'from tblRequestMaster RM_0to5LEFT JOIN tblRequestMaster RM_6to10 on (RM_6to10.fldPriorityCode between 1 and 5 AND RM_6to10.fldRequestDate Between '01-01-2007' and '08-05-2007')LEFT JOIN tblRequestMaster RM_11ormore on (RM_11ormore.fldPriorityCode between 1 and 5 AND RM_11ormore.fldRequestDate Between '01-01-2007' and '08-05-2007')WHERE RM_1to5.fldPriorityCode between 1 and 5 AND RM_1to5.fldRequestDate between '01-01-2007' and '08-05-2007' AND RM_1to5.fldRequestFlag like 'D' AND RM_1to5.fldRequestStatus = 'Y' AND RM_6to10.fldRequestFlag like 'D' AND RM_6to10.fldRequestStatus = 'Y' AND RM_11ormore.fldRequestFlag like 'D' AND RM_11ormore.fldRequestStatus = 'Y'group by RM_1to5.fldPriorityCode Odds are, that query won't work. But it should give you an idea of what your final query should look like.
  18. Yahweh

    Recordset error

    Odds are, when you moved your code, you moved it into a place where your connection hasn't been opened yet. Make sure you've moved the line "myConn.Open someDSN" with your other code.
  19. Its not very clear what you're trying to do. If you want to loop through your records in a database, do this:<% Dim conn, rs, sqlSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.Recordset")sql = "Select * from table"Conn.open some_connection_stringRS.Open sql, conn, 1, 1 Do until rs. eof response.write rs("field1") response.write rs("field2") response.write rs("field3") rs.movenext LoopRS.CloseConn.close %> That loops through all the rows in your table. You don't usually need a For Each unless you don't know the names of your columns.If you didn't know the names of your fields ahead of time, then you'd do something like this: <% Dim conn, rs, field sqlSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.Recordset")Set Field = Server.CreateObject("ADODB.Field")sql = "Select * from table"Conn.open some_connection_stringRS.Open sql, conn, 1, 1 Do until rs. eof for each field in rs.fields response.write field.name & ": " & field.value next rs.movenext LoopRS.CloseConn.close %>
  20. Who?The problem is on lines 38 and 39:Set Conn = Server.CreateObject("ADODB.Connection")Set Conn = Server.CreateObject("ADODB.RecordSet") You're setting the Conn variable twice. That should say: Set Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.RecordSet") Also, the string on line 41 says this: SQL = "Select Username, Password, IPAddress, Email, DateRegistered FROM Users WHERE " & _ "Username = '" & SQLSecurity(Username) & "' Limit 1; The string isn't closed, it needs an double-quote at the end of the line like this: SQL = "Select Username, Password, IPAddress, Email, DateRegistered FROM Users WHERE " & _ "Username = '" & SQLSecurity(Username) & "' Limit 1;"
  21. Yahweh

    Sort A Treeview

    Yes, actually I did. I found that article too, and I was sorely disappointed when my code didn't compile, it returned a the error I'm creating a website, not a desktop application. The sort method applies to System.Windows.Forms.Treeview, but not to System.Web.UI.WebControls.Treeview. See for yourself.I think maybe a programmer at Microsoft was lazy and forgot to add that little function to the TreeView web control.
  22. Yahweh

    Urgent Problem!

    I haven't tested it, but this should work: select artigo,pvpfrom precos inner join clientes on clientes.tppreco=precos.linprcLEFT JOIN artigoswhere (artigo<>'' and codigo <> '' AND clientes.numero=25) AND (artigo <> codigo AND pvpsiva <> pvp) I don't know what your table looks like, so I can't say if thats the most efficient query.
  23. That doesn't work if records have been deleted. For example:ID--1234567 User deletes record 6: ID--123457 When users run your query, they'll get an empty set.I suggest this query: SELECT TOP (1) *FROM table1WHERE id in ( Select TOP (2) id FROM table1 ORDER BY id DESC )ORDER BY ID ASC MySQL equivalent: SELECT * from table1 ORDER BY ID DESC Limit 2, 1
  24. Yahweh

    Sort A Treeview

    Basically, I'm storing a directory tree in an XML file and displaying it in a treeview.The XML file looks like this: <?xml version="1.0" encoding="utf-8"?><folder name="root"> <folder name="level1"> <folder name="level1.1"> <file name="kitties.aspx" /> <file name="bunnies.aspx" /> </folder> <file name="firstpage.aspx" /> <file name="secondpage.aspx" /> <file name="anotherpage.aspx" /> </folder> <folder name="level2"> <file name="somepage.aspx" /> <file name="default.aspx" /> </folder> <file name="default.aspx" /> <folder name="level3" /></folder> I can load the XML file into a treeview, but unfortunately, it doesn't display right. It sorts nodes in the order that I add them to the file, when I'd like to have them sorted alphabetically.Is there a convenient to way to sort my treeview?
  25. Yahweh

    Recordset error

    The 0 means you're opening your recordset in forward-only, read-only mode. The 3 means you're opening your record in insert mode. You can't be in forward-only mode and insert mode at the same time, that creates a conflict.Use this instead:rsInfo.Open strSQL, myConn, 3, 3 'adOpenStatic, adLockOptimistic FYI, "Select * from table1" is a terrible way to insert data, because when open the recordset, you're still executing and SQL statement that retrieves all records and all columns from the table that you don't do anything with. That's a bad thing, you'll bring your database to its knees after the first few dozen records.If you want to open your table with a Select statement, then at least open an empty recordset like this:Select * from table1 where 0 = 1 But, if you want the best performance, you should use an insert statement. That's most efficient to do things because ADO is executing the same insert query behind the scenes. Using RS.Addnew, you have to execute at least 2 queries (one for the select, the other for the insert), rather than just one. Try inserting records like this: Private Function SafeSQL(strString) strString = replace(strString, "'", "''") strString = replace(strString, "\", "\\") SafeSQL = strStringEnd FunctionDim conn, sqlSet Conn = Server.CreateObject("ADODB.Connection")Conn.Open someDSN sql = "INSERT INTO table1 (col1, col2, col3) VALUES ('[val1]', '[val2]', '[val3]');" 'I like to use Replace statements because its a little easier to set up my SQL statement sql = Replace(sql, "[val1]", SafeSQL(var1), 1, -1, vbTextCompare) sql = Replace(sql, "[val2]", SafeSQL(var2), 1, -1, vbTextCompare) sql = Replace(sql, "[val3]", SafeSQL(var3), 1, -1, vbTextCompare) Conn.Execute(sql)Conn.Close You'll get a lot better performance out of your database.
×
×
  • Create New...