ADO.NET :: Can't Pass DataReader Values

Nov 1, 2010

Why can I not call the global variables CatCode and CompanyName which are equated in the first procedure GetCompanyCatID And use their new values in the second procedure UpdateCompanyCounts as parameter values. When I hard code them code their values at the end of the GetCompany CatID procedure the following procedure updates properly.

string CatCode; - delcared global
string CompanyName; - delcared global
protected void GetCompanyCatID()
{
LinkID2 = Request.QueryString["linkid"].ToString();
string L_ID = LinkID2;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString001"].ConnectionString);
SqlCommand cmd = new SqlCommand("GetCID", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@L_ID", L_ID);
try
{
con.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
if (reader["CG_ID"] != System.DBNull.Value)
CatCode = (string)reader["CG_ID"];
CompanyName = (string)reader["CG_Name"];
}
}
}
catch (SqlException exc)
{ }
finally
{ con.Close(); }
// ******* HARD CODED to test below update procedure, it works. When commented out the following update procedure does not update.
CatCode = "55555"
CompanyName = "Test";
UpdateCompanyCounts();
}
protected void UpdateCompanyCounts()
{
LinkID2 = Request.QueryString["linkid"].ToString();
string L_ID = LinkID2;
string CatCode2 = CatCode;
string CompanyName2 = CompanyName;
// string CatCode2 = "23456";
// string CompanyName2 = "TEST";
SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString001"].ConnectionString);
SqlCommand cmd2 = new SqlCommand("UpdateCatCounter", con2);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.AddWithValue("@L_ID", LinkID2);
cmd2.Parameters.AddWithValue("@CG_ID", CatCode2 );
cmd2.Parameters.AddWithValue("@CG_Name", CompanyName2 );
try
{
con2.Open();
cmd2.ExecuteNonQuery();
}
catch (SqlException exc)
{
// ErrorBox.Text += string.Format("Error: {0}<br/>", exc.Message);
}
finally
{
con2.Close();
}
}

View 5 Replies


Similar Messages:

ADO.NET :: Check For Null Values From DataReader

Feb 16, 2011

I have the following code

public class ProductDetails
{
private string _productid;
public string ProductID
{
get { return _productid; }
}
private string _description;
public string Description
{
get { return _description; }
}
private string _image;
public string Image
{
get { return _image; }
}
public ProductDetails(string productid, string description, string image)
{
_productid = productid;
_description = description;
_image = image;
}
}
public class DataAccess
{
private static string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
public ProductDetails GetProductDetails()
{
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("ProductDetails", con);
cmd.CommandType = CommandType.StoredProcedure;
string productid = HttpContext.Current.Request.QueryString["productid"];
cmd.Parameters.Add(new SqlParameter("productid", SqlDbType.NVarChar)).Value = productid;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
ProductDetails pro = new ProductDetails(
(string)reader["ProductID"], (string)reader["Description"], (string)reader["Image"]);
reader.Close();
return pro;
}
}
protected void PopulateControls()
private DataAccess da = new DataAccess();
{
ProductDetails product = da.GetProductDetails();
if (product.Description == String.Empty)
{
lblDescription.Visible = false;
}
else
{
lblDescription.Text = product.Description;
}
}

In the last piece i want to check if the Description field is null or empty in order to hide the label control but i get an error if i write: if (product.Description == DBNull.Value) and can only use ring.Empty. But i want to check for NULL values as well..

View 3 Replies

Web Forms :: Setting Checkbox Values Through Datareader

Feb 3, 2011

I have a form with a checkbox list, the values of which are value = "1" value = "2' ...etc (amount of boxes not fixed). These values correspond to an id field in a database and are stored when a new user is entered. When reloading this info I want to populate the checkboxes according to how the user originally checked them.
What is the correct way to do this?

while (reader.Read())
(
i = Convert.ToInt16(reader["Id"]);
CheckboxList1.Items.FindByValue[i].Selected = true;
}

doesn't work....

View 3 Replies

Datareader Vs Dataset - Get The Number Of Rows From The Datareader?

Nov 15, 2010

I'm having a method that exports content from the database to excel files. The method taks as paramaters a DataReader param and a int param - the number of rows. For the number of rows i'm using a dataset, wich i fill using the same query as for the datareader. So I'm executing it twice... Is there a way I can avoid that? get the number of rows from the datareader?

View 1 Replies

C# - Already An Open DataReader Associated With This Command - When I'm Not Using Datareader

Jul 28, 2010

I am getting an error that an open DataReader associated with this Command, when I'm not using datareader(though probably executereader() is the same thing) how would I close this if I don't have a datareader present?

using (SqlConnection conn = new SqlConnection(ConnectionString))
{
SqlCommand cmd = new SqlCommand("spSelectAllTypes",conn);
cmd.CommandType = CommandType.StoredProcedure;
[code]...

I just want to be able to databind a bunch of dropdownlist in one open connection. (before I had multiple open and closes for each control)

View 2 Replies

Pass Values From One Page To Another?

Mar 17, 2010

i have one scenario in which i have to pass values from one page to another for that currently i am using querystring but now the values are more so i want to remove querystring and i dont want to user session as well and so i have tried using Hiddenfields but after redirecting to another page the values are cleared from all the hidden fields.

View 14 Replies

How To Pass Values Between ASCX

Feb 14, 2010

How to pass values between ASCX ?/

View 1 Replies

How To Pass Values To The Web Service

Jan 27, 2010

I would like to discuse with u, now i have one problem, ie, how could i pass value from the code behind to the web service, in that ,i have to pass 3 values,1, context key2, prefix text3, dropdown selected text or value, ( Contains Designation Details)how could i pass this 3rd value

View 1 Replies

C# - Pass Values To Other Pages?

May 5, 2010

i am trying here is to pass values to other pages. When i include the following code

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm5.aspx?Name="+txtName.Text);

[code]...

View 3 Replies

How To Pass Values To Javascript From Code Behind

Oct 28, 2010

Basically I want to display a popup box only at a specific time in asp.net application. so i'm using the following

[code]....

but this code is not working. the alert box is not popping up. is this a correct method to pass values to the script?. or what else to be done to meet the requirement?.

View 1 Replies

Way To Use Hyperlinks That Can Pass Additional Values

Jun 17, 2010

I guarantee the title of my thread does not explain what I am looking for, but I just can't think of a better way to word it. What I have right now is an application that the user can add, search, and update various orders in the System. I've been working on the front end page, and wanted to display a summary of all orders performed this month. Right now the Orders are represented as labels (based on data pulled from the database). What i'd like to do is replace these labels with hyperlinks. I was hoping that by doing that I could somehow write some code so that when an order is clicked that the user is taken directly to the search page and that order is displayed.

View 6 Replies

How To Pass Values From Querystring To JavaScript

Nov 4, 2010

Now that i learned how to pass values to an SWF object via flashvars, how can i pass values from a querystring to javascript?

What do i mean? In the following example i hard-code the xml file to load in the SWF object.

<script type="text/javascript">
var so = new SWFObject("preview.swf", "", "100%", "100%", "9", "#ffffff");
so.addParam("allowFullScreen", "true");
so.addParam("scale", "noscale");
so.addParam("menu", "false");
so.addVariable("xmlPath", "xml/exampleData.xml");
so.write("flashcontent");
</script>

Since the Xml file is created dynamic, the xml should be loaded from the value of a query-string. (I guess).

Supposing my url is http://www.example.com/load.aspx?XmlFile=SomeData

How can i pass it to the javascript side? Like..

so.addVariable("xmlPath", "xml/<% SomeData %>.xml");

or whatever it needs to make it work.

UPDATE: Besides the above example, is there any way of creating the JavaScript, in server-side?

View 3 Replies

How To Pass List Of Values To Silverlight

Sep 13, 2010

I want to pass the data from asp.net to silverlight.I tried for jquery to pass data from asp.net to silverlight.but it not working.

View 2 Replies

How To Pass Objects Not Values Between Pages In C#

Mar 8, 2011

At the moment I pass values from one page to another. I need to pass objects between pages, how can I do this.

View 3 Replies

How To Pass Values To A Javascipt Array

Oct 6, 2010

I am trying to implement the autocomplete method for textboxes.

I would like to use the example based on jquerys autocomplete provided here

<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("input#autocomplete").autocomplete({
source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
});
});
</script>
</head>

The first and Main problem is that i do not know the way of passing my values to the source:

By saying that i mean, supposing i have a a server-side ASP.NET function GetTheResults as listof(string) or GetTheResults as string ()

how am i supposed to pass those values as source required by the auto-complete?

The second problem is that the specific way does not use AJAX.
Which means i guess on the load of the form i will load all the available values to the source. Isn't that an overkill?

View 2 Replies

Pass Session Values To A Subdomain In .net?

Jun 17, 2010

I would like to know the method of passing session variables/values to a subdomain from the main website.For eg : Upon user login, I would like to set some session variables and redirect the page to a subdomain URL.

How can this be done? fyi... I have setup two websites in IIS. One is localhost and the other is subdomain.localhost

So, If I want to retrieve the session values in subdomain.localhost (which points to a specific folder in the app), how should I go about it?

View 2 Replies

Pass Values Between Pages With Gridviews?

Jun 13, 2010

I enabled the selection on my gridview. The question is, I can pass values with buttons but it seems redundant, because I have selection linkbuttons. So how can I pass variables with them ?

View 1 Replies

C# - Pass Values To A View In Sql Server

Sep 1, 2010

I have created a view called business this runs sucessfully ,but the problem is how will i use dynamic values in place of 12.925432,77.5940171 ,I want to pass parameter in sql query from c# code behind.

create view [dbo].[business] as
SELECT Id,
Name1,
ZipCode,
StreetName,
StreetNumber,

[Code]...

View 1 Replies

VS 2010 - How To Pass Values Between Pages

Mar 15, 2012

I have the beginnings or near endings of a data search web application. My first significant ASP.Net application. I understand how to do this in Calssic ASP but ASP.Net it quite different. I have 3 Pages:

(1)Search Parameters Page
(2)Results Page
(3)Details Page

What would the recommended method be for passing search parameters from page 1 to page 2 then to page 3 and back?

The challenge here is that on page 3, I allow paging through other records related to the record selected in a gridview on page 2. When done paging through these records on page 3, I want to return to page 2 with the same results and gridview page I left from on my way to page 3 originally.

I also may need to display the details on page 3 from some other source page.

These questions come up because I have:
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>

In page 2 that tells this page to get its values from public properties exposed in page 1 (Default.aspx)

Page 3 has:
<%@ PreviousPageType VirtualPath="~/AssessSearchResults.aspx" %>
to get public property values from page 2.

This is the start page: [URL] ....

I also have a very similar application in Classic ASP here: [URL] ....

View 2 Replies

Web Forms :: How To Allow Two Values: 20 And 40 To Pass Validation In A Text Box

Mar 15, 2010

im rather new to this and unsure of how to complete the task in the title. I currently have a text box called txtmodule, i want to restict the user from entering any number except 20 or 40. How can i do this using a RegularExpressionValidator or is there a better way?

View 4 Replies

Web Forms :: How To Pass Null Values To Database

Nov 3, 2010

my table field allows null values. but my code below does not work unless a value is assigned to my variable even though the glable variable is initialised to 0; tried the DBNull.Value - still, it gives me error as the table in question is linked and expecting a value.

[Code]....

View 10 Replies

JQuery :: How To Pass The Values As A Daterange To Datepicker

Aug 31, 2010

I have two dates (StartDate, EndDate) coming from sql database, stored in a table. How would I pass the values as a daterange to jquery datepicker?

View 3 Replies

State Management :: How To Pass Values From One Webpage To Another

May 31, 2010

i need to pass the roll no from one page to another and have written the code but the code is not working

in the first page

Response.Redirect("userview.aspx?RollNo=" & TextBox1.Text)

then in the target page

dim rollno1 as string
Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

View 14 Replies

C# - Pass Null Values From Code Behind With Textboxes?

Apr 28, 2010

I have two textboxes and a drop down.User has a option that he should select drop down and enter value in any one of the texbox .

My procedure accepts null values . only problem is how to pass tht from code behind tht the any text box value submitted it shud return the data.

View 2 Replies

Web Forms :: Pass Values From Parent To IFrame?

Aug 5, 2010

I am trying to write a simple application that will allow a user to pass a value from the parent page to a textbox in an IFrame.

Parent Page will only contain 3 controls (label, textbox, and a button). Once a user fills in the txtbox and then clicks the button I want the value that was put in the textbox to be sent to a textbox within an IFrame.

IFrame will contain a label, a textbox, and a button. Once the value is passed from the parent's textbox control to the iframe I want to also fire a button event in the iframe that will simply be:

[code]...

I am not worried about passing the value back to the parent page. My goal here is to create a testing application for my website. I want to automatically populate textbox's / radio buttons / date time pickers within an IFrame from a parent webpage. I am determining the stress on the server and testing the functional aspect of the iframe's website.

View 6 Replies







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