<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>ASP Message Board - Database (ADO/SQL/Access)</title>
		<link>http://www.aspmessageboard.com/</link>
		<description><![CDATA[Having trouble connecting to a
database? ADO giving you problems? If
you're confused about a
database-related issue, here's the
place to ask!]]></description>
		<language>en</language>
		<lastBuildDate>Thu, 20 Jun 2013 11:24:39 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.aspmessageboard.com/images/misc/rss.png</url>
			<title>ASP Message Board - Database (ADO/SQL/Access)</title>
			<link>http://www.aspmessageboard.com/</link>
		</image>
		<item>
			<title>Seeking better performance</title>
			<link>http://www.aspmessageboard.com/showthread.php?237615-Seeking-better-performance&amp;goto=newpost</link>
			<pubDate>Fri, 14 Jun 2013 22:31:43 GMT</pubDate>
			<description>Code: 
--------- 
CREATE PROCEDURE D_Tigers  
@RestId binary(20) 
AS  
DECLARE @Table table ( id binary (20) )  
DECLARE @Id binary(20) 
DECLARE...</description>
			<content:encoded><![CDATA[<div><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">CREATE PROCEDURE D_Tigers <br />
@RestId binary(20)<br />
AS <br />
DECLARE @Table table ( id binary (20) ) <br />
DECLARE @Id binary(20)<br />
DECLARE @Result bit <br />
SET @Result = 0 <br />
<br />
IF (SELECT restId FROM tblRest WHERE restId=@RestId AND restParentId&lt;&gt;@RestId) = @RestId<br />
BEGIN<br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblRest WHERE restId=@RestId <br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblBrawl WHERE restId=@RestId <br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblBook WHERE restId=@RestId <br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblIndie WHERE restId=@RestId <br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblScore WHERE restId=@RestId <br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblBlock WHERE restId=@RestId <br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblItem WHERE restId=@RestId <br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblStone WHERE restId=@RestId <br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblBlob WHERE restId=@RestId <br />
&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblSecret WHERE restId=@RestId <br />
END<br />
ELSE<br />
BEGIN<br />
&nbsp; &nbsp; &nbsp; &nbsp; INSERT INTO @Table SELECT restId FROM tblRest WHERE restParentId=@RestId<br />
&nbsp; &nbsp; &nbsp; &nbsp; WHILE ( SELECT COUNT(id) FROM @Table ) &gt; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; BEGIN<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET @Id = (SELECT TOP 1 id FROM @Table ORDER BY id ASC)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblRest WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblBrawl WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblBook WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblIndie WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblScore WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblBlock WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblItem WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblStone WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblBlob WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM tblSecret WHERE restId=@Id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM @Table WHERE id=@Id<br />
&nbsp; &nbsp; &nbsp; &nbsp; END<br />
END<br />
SET @Result = 1 <br />
SELECT @Result<br />
GO</code><hr />
</div> </div>

 ]]></content:encoded>
			<category domain="http://www.aspmessageboard.com/forumdisplay.php?5-Database-(ADO-SQL-Access)">Database (ADO/SQL/Access)</category>
			<dc:creator>sbhmf</dc:creator>
			<guid isPermaLink="true">http://www.aspmessageboard.com/showthread.php?237615-Seeking-better-performance</guid>
		</item>
		<item>
			<title>paging with custom class objects</title>
			<link>http://www.aspmessageboard.com/showthread.php?237609-paging-with-custom-class-objects&amp;goto=newpost</link>
			<pubDate>Sat, 08 Jun 2013 09:34:43 GMT</pubDate>
			<description>Hi, 
 
I have created some custom class objects. 
 
public class astroObjects 
{ 
 
public int Id { get; set; } 
 
public String Name { get; set; }</description>
			<content:encoded><![CDATA[<div>Hi,<br />
<br />
I have created some custom class objects.<br />
<br />
public class astroObjects<br />
{<br />
<br />
public int Id { get; set; }<br />
<br />
public String Name { get; set; }<br />
<br />
public String Desc { get; set; }<br />
<br />
public int CatId { get; set; }<br />
<br />
public String ImageThumb { get; set; }<br />
<br />
}<br />
<br />
My data is stored in an SQL database.<br />
<br />
When I want to display the data I query the database and make a list as so.<br />
<br />
public static List&lt;astroObjects&gt; GetAstroObjects(int catId)<br />
{<br />
List&lt;astroObjects&gt; astroobjects = new List&lt;astroObjects&gt;();<br />
<br />
// Do all sql work including setting up connection, command, ect.<br />
<br />
SqlConnection conn;<br />
SqlCommand comm;<br />
SqlDataReader reader;<br />
String mySQL;<br />
<br />
int thecatid = catId;<br />
<br />
mySQL = &quot;SELECT objectName, object_id, Desc, objectThumbnail WHERE CatId = @catId ORDER BY objectName&quot;;<br />
<br />
<br />
string connectionString = ConfigurationManager.ConnectionStrings[&quot;myConnectionString&quot;].ConnectionString;<br />
conn = new SqlConnection(connectionString);<br />
comm = new SqlCommand(mySQL, conn);<br />
<br />
comm.Parameters.Add(&quot;@catid&quot;, System.Data.SqlDbType.Int);<br />
comm.Parameters[&quot;@catid&quot;].Value = thecatid;<br />
<br />
<br />
conn.Open();<br />
<br />
reader = comm.ExecuteReader();<br />
<br />
<br />
while (reader.Read())<br />
{<br />
<br />
astroObjects c = new astroObjects();<br />
c.Name = reader[&quot;ObjectName&quot;].ToString();<br />
<br />
c.Desc = reader[&quot;Desc&quot;].ToString();<br />
<br />
c.Id = Convert.ToInt16( reader[&quot;object_id&quot;]);<br />
c.ImageThumb=reader[&quot;ObjectThumbnail&quot;].ToString();<br />
<br />
astroobjects.Add(c);<br />
}<br />
<br />
return astroobjects;<br />
}<br />
<br />
I next want to bind this list to a datalist.<br />
<br />
Most examples of paging to datalist on the web I have seen are using dataset but I read this old article online <a rel="nofollow" href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=345" target="_blank">http://www.dotnetcurry.com/ShowArticle.aspx?ID=345</a> that says you can just bind to a pageddatasource so have done the following:<br />
<br />
protected void getTheData(int catid)<br />
<br />
{<br />
<br />
PagedDataSource page = new PagedDataSource();<br />
<br />
page.AllowCustomPaging = true;<br />
page.AllowPaging = true;<br />
<br />
page.DataSource = myproject.astroObjects.GetAstroObjects(catid); <br />
page.PageSize = 10;<br />
<br />
page.CurrentPageIndex = CurPage; <br />
<br />
Decimal intNumRecs;<br />
intNumRecs = 50;//need to replace with actual number of records returned in the query <br />
<br />
Decimal numPages;<br />
numPages = Math.Ceiling(intNumRecs / page.PageSize); <br />
<br />
int strCurPage;<br />
strCurPage = Convert.ToInt16(CurPage) + 1; <br />
<br />
LabelCurrentPage.Text = &quot;Pg: &quot; + strCurPage + &quot; of &quot; + numPages + &quot; (&quot; + intNumRecs + &quot; objects)&quot;;<br />
<br />
ButtonBack.Visible = (!page.IsFirstPage);<br />
ButtonNext.Visible = (!page.IsLastPage);<br />
<br />
DataList1.DataSource = page;<br />
<br />
DataList1.DataBind();<br />
<br />
}<br />
<br />
and here's the code for my next and previous buttons<br />
<br />
public void Next_Click(Object obj, EventArgs e)<br />
{<br />
<br />
<br />
//identify current datafilter<br />
<br />
CurPage += 1;<br />
<br />
getTheData(Convert.ToInt16(ViewState[&quot;DataFilterId&quot;]));<br />
<br />
<br />
}<br />
<br />
<br />
<br />
public void Prev_Click(Object obj, EventArgs e)<br />
{<br />
<br />
<br />
CurPage -= 1;<br />
<br />
getTheData(Convert.ToInt16(ViewState[&quot;DataFilterId&quot;]));<br />
}<br />
<br />
<br />
<br />
and here's my page load code <br />
<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
<br />
checkloggedin();<br />
<br />
if (!IsPostBack) //if page loaded for the first time<br />
{<br />
<br />
CurPage = 0;<br />
getTheData(0);<br />
<br />
<br />
}<br />
<br />
if (IsPostBack) //if page has already loaded<br />
{<br />
<br />
CurPage = Convert.ToInt32(ViewState[&quot;CurPage&quot;]);<br />
getTheData(Convert.ToInt16(ViewState[&quot;DataFilterId&quot;]));<br />
<br />
}<br />
<br />
<br />
<br />
}<br />
<br />
Here's how I set CurPage variable (Current page)<br />
<br />
<br />
public int CurPage<br />
{<br />
get<br />
{<br />
if (this.ViewState[&quot;CurPage&quot;] == null)<br />
return 0;<br />
else<br />
<br />
return Convert.ToInt16(this.ViewState[&quot;CurPage&quot;].ToString());<br />
<br />
}<br />
set<br />
{<br />
this.ViewState[&quot;CurPage&quot;] = value;<br />
}<br />
<br />
}<br />
<br />
and here's how I handle DataFilterId variable (category in the query)<br />
<br />
public int DataFilterId<br />
{<br />
<br />
get<br />
{<br />
if (this.ViewState[&quot;DataFilterId&quot;] == null)<br />
return 0;<br />
else<br />
<br />
return Convert.ToInt16(this.ViewState[&quot;DataFilterId&quot;].ToString());<br />
<br />
}<br />
set<br />
{<br />
this.ViewState[&quot;DataFilterId&quot;] = value;<br />
}<br />
}<br />
<br />
When I visit the page 10 records are displayed as expected. However when I click the next button the next 10 records aren't shown but the right page number is.<br />
<br />
I can't figure why this isn't working.<br />
<br />
The article uses Linq and I want to just do an SQL query as in the my list code above. I need to just query database so just the amount of records I need are retrieved from the database and added to the list.<br />
<br />
Hope some one can help me.<br />
<br />
Cheers<br />
<br />
Mark :)</div>

 ]]></content:encoded>
			<category domain="http://www.aspmessageboard.com/forumdisplay.php?5-Database-(ADO-SQL-Access)">Database (ADO/SQL/Access)</category>
			<dc:creator>markbpriv</dc:creator>
			<guid isPermaLink="true">http://www.aspmessageboard.com/showthread.php?237609-paging-with-custom-class-objects</guid>
		</item>
		<item>
			<title>Problems using the SQL duplicates code from SQL Guru on this site</title>
			<link>http://www.aspmessageboard.com/showthread.php?237601-Problems-using-the-SQL-duplicates-code-from-SQL-Guru-on-this-site&amp;goto=newpost</link>
			<pubDate>Fri, 24 May 2013 03:49:56 GMT</pubDate>
			<description>I used the following code (adapted from a posting from SQL Guru).  However, I am getting the error at the bottom: 
 
 DELETE FROM tbl_events_temp...</description>
			<content:encoded><![CDATA[<div>I used the following code (adapted from a posting from SQL Guru).  However, I am getting the error at the bottom:<br />
<br />
 DELETE FROM tbl_events_temp WHERE tbl_events_temp.event_id IN (<br />
SELECT F.event_id<br />
FROM tbl_events_temp AS F<br />
WHERE EXISTS (<br />
<br />
SELECT airport_id, event_from, Count( event_id )<br />
FROM tbl_events_temp<br />
WHERE tbl_events_temp.airport_id = F.airport_id<br />
AND tbl_events_temp.event_from = F.event_from<br />
AND tbl_events_temp.airport_id != ''<br />
GROUP BY tbl_events_temp.airport_id, tbl_events_temp.event_from<br />
HAVING Count( tbl_events_temp.event_id ) &gt;1<br />
)<br />
)<br />
AND tbl_events_temp.event_id NOT<br />
IN (<br />
<br />
SELECT Min( event_id )<br />
FROM tbl_events_temp AS F<br />
WHERE EXISTS (<br />
<br />
SELECT airport_id, event_from, Count( event_id )<br />
FROM tbl_events_temp<br />
WHERE tbl_events_temp.airport_id = F.airport_id<br />
AND tbl_events_temp.event_from = F.event_from<br />
GROUP BY tbl_events_temp.airport_id, tbl_events_temp.event_from<br />
HAVING Count( tbl_events_temp.event_id ) &gt;1<br />
)<br />
GROUP BY airport_id, event_from<br />
)<br />
<br />
MySQL said: Documentation<br />
#1093 - You can't specify target table 'tbl_events_temp' for update in FROM clause</div>

 ]]></content:encoded>
			<category domain="http://www.aspmessageboard.com/forumdisplay.php?5-Database-(ADO-SQL-Access)">Database (ADO/SQL/Access)</category>
			<dc:creator>jeffsimon</dc:creator>
			<guid isPermaLink="true">http://www.aspmessageboard.com/showthread.php?237601-Problems-using-the-SQL-duplicates-code-from-SQL-Guru-on-this-site</guid>
		</item>
		<item>
			<title>Weighting sql results</title>
			<link>http://www.aspmessageboard.com/showthread.php?237597-Weighting-sql-results&amp;goto=newpost</link>
			<pubDate>Tue, 21 May 2013 23:05:35 GMT</pubDate>
			<description><![CDATA[I'm using MSSQL2008. I have a table that I need to search one field for matches from a user input search string. I have a script that pieces together...]]></description>
			<content:encoded><![CDATA[<div>I'm using MSSQL2008. I have a table that I need to search one field for matches from a user input search string. I have a script that pieces together the SQL statement depending on how may words are in the search string.<br />
<br />
So far so good. Now I want to be able to sort the table so that the records that have the most matches of words in the search string will be first. To this end I have come up with this:<br />
<br />
Original Search String: &quot;The Tonic Tavern &amp; Kitchen&quot;<br />
<br />
Some script code converts that into the individual words &quot;Tonic&quot; and &quot;Tavern&quot; and &quot;Kitchen&quot;.<br />
<br />
SELECT v_name , <br />
(CASE WHEN v_name LIKE '%Tonic%' THEN 1 ELSE 0 END) AS weight0, <br />
(CASE WHEN v_name LIKE '%Tavern%' THEN 1 ELSE 0 END) AS weight1, <br />
(CASE WHEN v_name LIKE '%Kitchen%' THEN 1 ELSE 0 END) AS weight2, <br />
SUM(weight0+weight1+weight2+ 0) AS masterweight <br />
FROM ss_venue <br />
WHERE v_state = 'AZ' <br />
AND (v_name like '%Tonic%' OR v_name like '%Tavern%' OR v_name like '%Kitchen%' ) <br />
ORDER BY masterweight DESC<br />
<br />
Assuming the 3-word input, this is meant to give me column called &quot;masterweight&quot; with a value of 3 for records that match all terms, 2 for records that match 2 terms etc...<br />
<br />
I get an error that says &quot; Invalid column name 'weight0'. &quot; yet if I remove the &quot;SUM()&quot; and say ORDER BY weight0 at the end it's fine. So why is it a column one way and not the other??? What am I missing?</div>

 ]]></content:encoded>
			<category domain="http://www.aspmessageboard.com/forumdisplay.php?5-Database-(ADO-SQL-Access)">Database (ADO/SQL/Access)</category>
			<dc:creator>enigma65</dc:creator>
			<guid isPermaLink="true">http://www.aspmessageboard.com/showthread.php?237597-Weighting-sql-results</guid>
		</item>
	</channel>
</rss>
