VS 2010 - Query SQL Server From Within A Class

Nov 20, 2013

I have an application where I am trying to create a Content Management System for a set of newsletters. I use a SQL server to store all content, and have the connection string in the Web.Config. I use forms to allow users to enter articles and register to receive the newsletters. The app regularly generates the newsletters and emails them out. Since the processing of the newsletters does not need a form, I was considering using a class.

I am having trouble getting the datasets connected to the SQL database, and using the stored connection string. I am thinking it is something like:

Code:
Imports System.Data
Imports System.Data.SqlClient
Public Class clsProcessNewsletters
Dim strSql As String = "SELECT * FROM Users"
Dim dtb As New DataTable

[Code] .....

First of all is this an appropriate approach? And if so, any pointers on cleaning up the code?

View 7 Replies


Similar Messages:

Visual Studio 2010 - 2010/Windows 7 -> Can't Connect To Development Server?

May 18, 2010

I have a clean installation of Windows 7 with VS2010 RTM and am trying to get the ASP.NET Development Server to work. When I run the project, the WebDev server starts and shows that it's listening on port x on localhost. I've tried:telnet to the port. The port is not listening. running netstat -o shows that the WebDev server is in fact not listening on any port. manually changing the WebDev port to a different port and restarted VS without effect. I have Windows Firewall turned off entirely and am not running any other firewall software either.

View 1 Replies

VS 2010 - How To Do A Query From A Dataset

Aug 19, 2010

Can you do a query from a dataset?

Code:

Dim cmd As New SqlCommand
cmd.Connection = New SqlConnection(<connectionString here>)
cmd.Connection.Open()
cmd.CommandText = "Select * From table_name"
Dim da As New SqlDataAdapter(cmd.CommandText, cmd.Connection)
Dim ds As New DataSet
da.Fill(ds) ' I want to do some query with THIS dataset
cmd.Connection.Close()

I want to do a query based on the dataset ds. Let's say I want to filter out names that starts with "a". If yes, how do you do it?

View 11 Replies

VS 2010 - Call Procedure From A Class

Jun 10, 2012

Inside my application I created the following class

Code:
Public Class clsProject

Public Sub AddData(ByVal cproject As string)
...
end Sub
end Class

I want to call this procedure from a sub in a form. So in the code behind file I wrote

Code:
Imports TextMgmt.clsProject
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub btnAddData_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAddData.Click
Call clsProject.AddData(txtInput.text)
End Sub
End Class

I get the following design time error: Reference to a non-shared member requires an object reference.I thought making things Public would make them visible.

View 2 Replies

DataSource Controls :: Can't Find Query's / By Right Clicking On Database Created A Query In Server Explorer?

May 17, 2010

By right clicking on my database i created a query in server explorer. But where are this query stored can't find them back. I should aspect that their is a folder query's like there is a folder tables but this isn't the case.

View 10 Replies

SQL Server :: Sub Query In Cross Table Query To Create Statistics

Mar 2, 2011

I am trying to create statitics for game downloads and am having dificulty with a sub part of my query. the goup by command is not having the disired result and i think i have been looking at it too long to see what i am doing wrong. [Code]....

At the moment it is producing each result in many rows when only 4 rows should appear. its the download column that is doing it. needs to be sub queried or something to display total in relation to month,gameid,userid.

Month-download-GameID-UserID

1 1
1 1

1 1
1 1

View 2 Replies

SQL Server :: Query Slow In Loading / Trying To Display Query Result?

Feb 1, 2011

I am trying to display this query result in an aspx page.

It is very slow in loading. Here is the query. The inner query inside the outer quesry is the problem.(Please see the underlined part in the query) - (If I remove that part it is very fast.)

select

top 500

--This column is the issue
,Governing_Class=( case when exists (select top 1 tqc.class_code from
t_quote_class tqc
inner join t_quote_class_premium tqcm on tqc.class_code =tqcm.
class_code
where tqc.appid=pi.appid and tqc.class_code not in('8742' ,'8810','7380')
order by tqcm.premium_amt desc
)
then ( select top 1 tqc.class_code from
t_quote_class tqc
inner join t_quote_class_premium tqcm on tqc.class_code =tqcm.
class_code
where tqc.appid=pi.
appid
order by tqcm.premium_amt desc
)
......... From tables

View 7 Replies

ADO.NET :: Display Data 1 / 2010 And Get Query?

Oct 15, 2010

which datatype is needed if I want to display the data 1 / 2010 and want to get query = select min (number) as number. Do I have to use a separate number and year?

View 2 Replies

VS 2010 - Doing Query And Update For SQL Database

Jul 2, 2011

Here's something I've been stuck on for some time. I used code from the ADO.NET Tutorial and tried to translate it so it applies to SQL and the database on my website. I set the Configuration Manager for Debug and so I can see a detailed error message.

Here's my code:

Option Strict On
Imports System.Web.AspNetHostingPermission
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Data.SqlDbType
Imports System.Data.Sql

[Code] .....

I have most of the lines in the DoStuff Sub commented out right now but I get the same error message either way so it's responding to the first line below Try.

Here's the error message I see. Line 52 is :
da.Fill(ds)

The table in Database1 that I'm trying to access is called Ray Rover Activation.

View 6 Replies

VS 2010 - Accessing CSS Class From Nested MasterPage

Sep 4, 2011

I'm changing the CSS of my menu items during runtime to reflect which page is currently being viewed. It works fine. But, I have a nested master page that needs to change the CSS of the master page's items. How I can access the master page's menu items?

Here's the menu:

Code:
<div class="Menu" id="TopMenu" runat="server">
<ul>
<li><a href="../Default.aspx" runat="server" id="HomeButton" class="ActiveMenuButton">
<span>Home</span></a></li>

[Code] ....

I need to access the InventoryButton ID, but am unable to directly.

View 3 Replies

Databases :: Oracle Query Convert To Sql Server Query

Sep 3, 2010

I am a biggner in SQL DB . but i started a complicated and painfull work in SQL SERVER 2008. the problem convert Oracle hierarchical query to SQL query. the query

SELECT DISTINCT
LEVEL LVL,
SCH.NSCHEDULE_SL,
SCH.NSCHEDULE_SL_FM,
SCH.CSHED_CNAME
FROM FA_SCHEDULES SCH
WHERE LEVEL = 1
AND NSCHEDULE_SL_FM IS NULL
AND NBRANCH_SL = 2
CONNECT BY PRIOR SCH.NSCHEDULE_SL_FM = SCH.NSCHEDULE_SL
AND NBRANCH_SL = 2

View 1 Replies

ADO.NET :: VWD 2010 And Linq To Sql: Can't Find A Query Model ?

Sep 19, 2010

I have added a linq to sql layer in my MVC 2 application.

This is the code I am using:

using (ProductPortalDataContext ctx = new ProductPortalDataContext())
{
var Title = from aps in ProductPortal.Models.AppSettingsView[code]...

It says to be unable to find a quey model for AppSettings view and then says "where not found".

Tried googling, nothing came up. Tried searching here(first two pages) and nothing that seemed relevant popped up.But the best of all, created a new ASP.NET applicatio, imported the model using Linq to SQL and it compiled!Ok, I tried adding a button and a label to the asp.net application just to see if it would work... guess what? It doesn't!Still the same error message and I have *NO* clue what's wrong with it!

View 8 Replies

VS 2010 - Page Property Values Query

Feb 20, 2015

I am working on a page whereby all the controls within the page get translated to another language.

This is handled within the master page prerender event and generally works fine.

However my page consists of a multiview control that is made up of 2 views. By default the INSERT formview is displayed so the user can enter form detials. This translates fine.

On clicking the save button the multiview active index is set to 1 and the EDIT formview displayed so as the user can update any of their details. This view does not get translated.

It would seem this is due to the controls not being available at this point in the page cycle or when this button event fires.

So i opted to do the translate process within the prerender event of the EDIT formview, and the method does have access to all the controls within this formview and runs after the master page prerender event. So all should be good.

However it seems that all th epage properties at this point in time are cleared. So the translation doesnt work. At the point of master page prerender i have verified they are populated with the values, but as soon as i hit the formview prerender all the page properties get cleared to nothing...

View 2 Replies

VS 2010 - Stop Execution Of MSSQL Query

Nov 21, 2013

i have a complex MSSQL query in my ASP.NET page with rows showing in GridView control.

I want to know what is the best solution for stopping the query if it takes more than X seconds to show in GridView.

View 6 Replies

VS 2010 / Refresh A Database Query And Listbox?

Jun 30, 2012

I have a dropdown list which provided input to a SQLDataSource query which is bound to a listbox. When the user changes the index of the dropdown box, I want to trigger the SQQLDataSource to requery the database, and repopulate the listbox.

I have set the autopostback = true for the dropdown box. I have also added a Response.Redirect back to the same page in the SelectedIndexChanged method, but the DataSource does not Repopulate. How to trigger the requery?

View 1 Replies

VS 2010 GridView - Show 'pretty Name' Of Class Property?

Jan 10, 2011

I have a class Person that represents a person in my database. This class has a CategoryId property (int) and a Category property (type Category).

Category is a class that represents a category in my database. csharp Code:
public class Person{ public int Id {get; set;} public string Firstname {get; set;} public string Lastname {get; set;} public int CategoryId {get; set;} public Category Category {get; set;}} public class Category{ public int Id {get; set;} public string CategoryName {get; set;}}
[code]....
I am displaying a list of these Persons in a GridView, and I would like to display the name of the Category (the CategoryName property to be precise). So I define this markup;

xml Code:
<asp:GridView runat="server" ID="personsGrid" AutoGenerateSelectButton="True" AutoGenerateColumns="False" DataKeyNames="Id"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" /> <asp:BoundField

Usually I would solve this problem by one of two ways:Override the ToString method of the Category class and return the name.
Add a readonly 'CategoryName' property to the Person class, where I return 'this.Category.CategoryName' (and then bind the column to this property instead).

In this case however, I am using the Entity Framework, and the Person and Category classes are automatically generated by the database model. I suppose I could edit the generated code manually, but I don't like that, since any change in the model will cause VS to re-generate the code and my changes would be lost. So these two methods are not going to work...

The simple question remains: how do I make the Category column show the CategoryName property of the object it represents, rather than just the type name?In a DropdownList for example (which I am already using for the user to select a category when creating a person), I can set the DataTextField (to "CategoryName") and DataValueField (to "Id") properties and it displays the right name and uses the right value (the Id). I can't find anything similar for a BoundField though... Am I overlooking something obvious?

Another solution would be if I could tell the Entity Framework model to add another property to my Person class which returns the CategoryName of the Category. I can't find any way to do that though (I am a compleet noob in EF),

View 5 Replies

Application Does Not Recognize Class File In App_Code VS 2010

Jan 23, 2011

Since App_Code doenst exist as an ASP.NET Folder, I manually added App_Code as a regular folder, then within that I placed technologydescriptor.cs. Although it now has the appearance of an ASP.NET Folder.But for some reason my code doesnt recognize this class if its w/in the App_Code folder. This is picked up if it is not within that folder- why?Error: "The type or namespace name could not be found, are you missing a using directive or assembly reference"

[Code]....

View 4 Replies

Visual Studio :: From VS2008 To VS 2010 Created A New Class?

May 20, 2010

I've just upgrade my web application from vs2008 to vs2010, I create a new web app from vs2010, then copy across all the existing files from vs2008, then I add a new class file to App_Code folder, the intellisense is not showing up for everything and class etc is also not color in the right color. However, when I open the existing class I created earlier from vs2008, intellisense just working fine and all classes are in different color as well, if I make a copy of existing class, the copied class does not support the intellisense as well. However, if I shut my VS, and reopen it, they all appear to be support with intellisense for existing class, but once I created a new class, intellisense is not support.

View 4 Replies

VS 2010 - Passing Image Control To Function In A Class?

Oct 31, 2012

I wrote a function in code behind of the aspx file to get from an SQL database the imageurl and assign it to that image's URL. This works fine so I decided to move it to a class but now the imageurl does not exist because the passed image control is now refering to system.drawing.image not the web image.

Code:
Public Sub ShowCodeImages(sProdCode As String, ByRef imgCode As Control, sConnectionString As String)

Dim sSQL As String
Dim sqlDCStock As New SqlConnection
Dim sqlDAStock As SqlDataAdapter
Dim sqlDTStock As DataTable

[Code] .....

View 1 Replies

VS 2010 - Can't Get Linq Query To Return Expected Results

Feb 13, 2014

I have a array list and am using like a database trying to search for ChildID and ParentID based on certain criteria.

My example below has the following keywords to search for:

Yellow, Mustard, Honey, Orange, Flame, Talisman

I also have a category volume value which I grab the first 2 characters to determine another filter.

My code isn't returning all matches with using 'Contains'. Right now it finds the 'Orange, Flame, Talisman'/AV record and returns 50, 28. My keywords also has 'Yellow, Mustard, Honey'/AV which should return 55 and 28 as well.

HTML Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="temp2.aspx.vb" Inherits="temp2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

[Code] ....

View 4 Replies

Visual Studio :: 2010 Tab Menu Changing The Class / Style?

Apr 20, 2010

I have a trial version of VS2010 and created a simple out of the box ASP .Net web application. I have been playing around with the css file for the project and have yet to figure out how to effect the menu tabs.

View 2 Replies

Visual Studio :: VS 2010 Crashes On Adding Class Attribute?

Jul 29, 2010

VS 2010 crashes instantly when I press = when adding the class attribute to anything.

The exact error I get is

Microsoft visual studio 2010 has stopped working.

Adding any other attribute works fine.

View 4 Replies

VS 2010 - Create Class To Return Data As List Object

Dec 4, 2013

I have a Google spreadsheet that I am reading data from and I want to load the data into a list object so I can use but I am having some issues.

Google Spreadsheet
-Worksheet name: Charts
-Tab: Color_Summarized
-Column 1: ColorSummary
-Column 2: ChildID
-Column 3: ParentID

sample rows:
Aqua|29|28
Blue|49|23
Yellow|55|28

My results are
Yellow Color_Summarized FH 55 28

How do I need to set it up so it keeps all the data loaded instead of just the last instance? Is there a better way then putting in class?

My code:

Code:
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Collections.Generic
Imports Google.GData.Spreadsheets

[code]....

View 3 Replies

SQL Server :: How To Copy Result Query To Another Query

Nov 4, 2010

i have tow query in one stored procedure

first query and the second one every of them return only value

i want to copy the result of tow values in a new row in new table

as i want to check on this tow values in ado.net

i want to get only this tow values as a row not first and secon query

only a row has result of first and second query results

[Code]....

View 3 Replies

SQL Server :: Select Second Query If First Query Returns Nothing?

Oct 14, 2010

How can I SELECT second if first SELECT returns nothing?

View 8 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved