How To Declare Variable In Enclosing Block
Jan 3, 2011If ((intCustomerCount Mod intColumns = 0) And (intCustomerCount > intColumns)) Or (intCustomerCount = intColumns) Then
View 3 RepliesIf ((intCustomerCount Mod intColumns = 0) And (intCustomerCount > intColumns)) Or (intCustomerCount = intColumns) Then
View 3 RepliesI'm am not quite sure why I am getting this error.
Dim numUsers as Integer
Using myConnection as New System.Data.SqlClient.SqlConnection("Data Source=(local);InitialCatalog=dbtest;Integrated Security=True")
Dim queryString As String = "SELECT COUNT(*) AS Num_Of_User FROM tblusers WHERE username=@username AND password=@password"
Using myCommand as New System.Data.SqlClient.SqlCommand(queryString, myConnection)
myConnection.Open
myCommand.Parameters.AddWithValue("@username", requestName)
myCommand.Parameters.AddWithValue("@password", requestPass)
numUsers = myCommand.ExecuteScalar()
End Using
End Using
This error occurs on the first using statment.
have a look at this simple code snippet
[Code]....
Here second declaration of x gives error that "variable 'x' hides a variable in an enclosing block. I wonder why this error is not given for second 'i' variable declared in second for loop?
Since i am declaring second x in a separate for block, why this error is given for variable second x ?
I have 2 separate code-block asp.Net expressions in an aspx markup, with an html content between (span element in the example below). In the first code-block, there is "i" as an increment variable for the for loop.Then the code-block is cut with an html content.And another code-block expression is opened but as I see I can reach the "i" variable which was declared in the previous code-block.
So, how asp.net handles -compiles- the pieces of code-block experrions declared in the mark up? Does it check the semi-colons and generates some anonymous methods which will end up with many calls to Response.Write in the last place?
<p>
<%for (int i = 0; i < 30; i++)
{
[code]....
Possible Duplicate: Use of var keyword in C# Hi, I am pretty new in C#,I would like to know the best practices in declaring variables.I know it is possible to use VAR (explicit declaration) or the DataType when declaring a variable (implicit).
View 3 RepliesNested GridView Control returns "Object variable or With block variable not set" when outer GridView returns rows.
The Nested GridView Control works as long as the outer GridView returns rows, the following code works: [Code]....
Object variable or With block variable not set.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object variable or With block variable not set.
Source Error:
Line 118: If e.Row.RowType = DataControlRowType.DataRow Then
Line 119: Dim myStatus_ID As SqlDataSource = CType(e.Row.FindControl("sqlDeviceStatusAssign"), SqlDataSource)
Line 120: If Not e.Row.DataItem("Status_ID") Is Nothing Then
Line 121: myStatus_ID.SelectParameters(0).DefaultValue = e.Row.DataItem("Status_ID")
Line 122: End If
I have tried checking for IsDbNull and checking to see if a label exists in a given row. This code *If Not e.Row.DataItem("Status_ID") Is Nothing Then* appears to do nothing.Same with the following:
*Dim localLblItemReference As Label = CType(e.Row.FindControl("lblItemReference"), Label)
*If Not localLblItemReference Is Nothing Then
******************************************************************************************
To further clarify my question above, I am looking for a method to detect e.Row.DataItem("Status_ID") is nothing/null due to the outer GridView returning 0 results in a query.I have a (Outer) GridView Control with another GridView Control inside of a template field with it's associated SqlDataSource control.
In the "Protected Sub GridViewReport_RowCreated", I provide the Select Parameter for the associated SqlDataSource with the DataItem row value.When the (Outer) GridView Control does not return any rows, the "e.Row.DataItem("Status_ID")" throws a:
Exception Details: System.NullReferenceException: Object variable or With block variable not set.
I am using three listviews on a page ... the first is always populated ... the other two are sometimes populated I want to total amounts and counts from all three ... so I set up steps in the DataBound events works great when all three listviews are populated the error "Object Variable or With block variable not set." occurs when LV2 or LV3 is not populated I've tried testing DataItem ... Is Nothing but get the failure on the If test instead
View 3 Repliesi want to declare variable for whole of my project , i mean for solution, where and how should i do it?
View 16 RepliesI heard that Global.asax file is optional in asp.net web application. But, if we need to declare any session variables in my website, do i really need to add Global.asax file and initialize session variables inside Session_Start() ?
View 1 RepliesI have an ENUM shown below that I would like to be able to use on multiple aspx pages. I would like to put it in a class (.vb) file in App_Code
I was not sure of how to declare it in the class file and then how to refer to it on the aspx pages.
Public Enum Slots
NotDefined = 0
Host = 1
Admin = 2
Seller1 = 3
Seller2 = 4
SellersAgent = 5
SellersAtty = 6
End Enum
Here are 3 scenarios:
namespace NS
{
public partial class A: System.Web.UI.UserControl
private Variable v;
protected void Page_Load(object sender, EventArgs e){
if (!Page.IsPostBack) v= new Variable();
....
}
}
namespace NS
{
public partial class A: System.Web.UI.UserControl
private Variable v = new Variable();
protected void Page_Load(object sender, EventArgs e){
}
}
namespace NS
{
public partial class A: System.Web.UI.UserControl
private Variable v;
protected void Page_Load(object sender, EventArgs e){
v = new Variable();
}
}
When does the variable "v" gets created every time for the 2nd scenario? Is the 2st scenario is equivalent to the 3rd one?
I've began working with asp.net mvc very recently and I've ran into a problem.I've got an aspx page which renders a few ascx pages. What I'd like to do is declare a global var at the aspx page so it is visible to all its childs. I tried <% var i = 0; %> but it wasn't visible at the child pages. What could I do?
View 4 Replieshow to Declare scalar variable
[Code]....
I Am getting error as Must declare the scalar variable "@Imageid" for the following code,while executing,
exec spGetPager  ' ' , ' ', ' 3 ', ' '
In my coding I pass querystring value like 1,2,3 etc
CREATE PROCEDURE spGetPager
@PageNo int = 1,
@ItemsPerPage int = 1,
@Imageid int,
[Code].....
I would like know how to declare a global variable that can be used within a user after the user login and before the user logout across all the possible pages.
I need to develop a web application that will connect to 5 different servers depends on the selection of user on what server they wish to connect and after they select a server and login...I will need to keep track the server name in a variable last until the user logout (user may visit various pages but the server name MUST NOT be changed due to other user login into different server). So how can I do it so that other users may select different servers and will keep the server name for each different users.
Let says:-
User A selects Server A and login and User B selects Server B and login at the same time, so how the global variable can handle the needs for each user (User A & B) with different server select?
Is "Session" the only way to fulfill the above? I think of using Application State but it seems that the value stored will be shared by all users and not for a particular user.
I am rather confused as how or where to declare this variable in asp.net.
[Code]....
Whenever i put this in my sqldatasource for it is asking me to Define Parameters:
The wizard has detected one or more parameters in your SELECT statement. For each parameter in the Select Statement, choose a source for the parameter's value.
How to declare a global variable or a public sub in a web application that all aspx pages can have access to?
View 5 RepliesI'm looking for a way to declare a global variable (so all pages could see) but personal (so if one user puts some value in it, it won't matter to another user or change his value).Sessions and hidden fields won't do. I've tried working with declaring keys in Web.config but unfortunely, the keys values aren't personal, and all users share the same key value.Another way I was thinking was maybe classes, but perhaps there might be an easier solution?
View 19 Replieswhen I am executing an above code and click on button to insert data is shows an error message
as:Â System.Data.SqlClient.SqlException: Must declare the scalar variable "@imagefile"
Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
Try
If fileupload1.HasFile Then
'getting length of uploaded file
[Code]....
I can't figure out whats wrong with my contact page. I am getting this error when executing. It complied fine, I see the page as it suppose to. Then I enter all my contact information and click submit I am getting this error. Can someone guide me. Here is the error msg
must declare the scalar variable @txtSubject Here is the part of relevant code
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim ContactDataSource As New SqlDataSource()
ContactDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString1").ToString()
ContactDataSource.InsertCommandType = SqlDataSourceCommandType.Text
ContactDataSource.InsertCommand = "INSERT INTO Enquery (EnqSubject,EnqFirstname, EnqLastname,EnqContactNumber,EnqEmail,EnqMsg,EnqDateTimeStamp,EnqIPAddress) values (@txtSubject, @txtFirstname, @txtLastname,@txtPhone,@txtEmail,@txtMsg, @txtDateTimeStamp,@txtIpAddress)"
[Code]....
I'm getting "Must declare the scalar variable "@ShowTypes"." when I try to run the code below.
[Code]....
i want to declare a variable in page load{} as global so that i can monitor it so that it is not recreated each time
View 4 RepliesHow do I define @UserName in my function:
[Code]....
I believe "UserName" = Me.User.Identity.Name
but I don't know the proper way to add it to the function.
OK, this may be a little difficult to explain, so I will try my best and post the code I currently have.
I have a table with a list of usernames. I have the list of usernames displayed on a page through a GridView. What I am attempting to do is for each username in the column "adminUsernames", I need to insert a set of values in another database table for EACH "adminUsernames" that exists. Example: There are 2 adminUsernames vales in 2 seperate rows. These are "Admin 1" and "Admin 2". For each adminUsername values (Admin 1, Admin 2), I need a row interted in another database table. Maybe the code that I have (that does not work) will help you see what is happening:
[Code]....
I keep receiving this error when running: [Code]....
how to declare global variable in master page and use it in all pages
View 1 Replies