?
Solved

Unassigned Local Variable??

Posted on 2009-03-30
1
Medium Priority
?
411 Views
Last Modified: 2012-05-06
Experts,

In the attached method, I'm getting an "unassigned local variable" on this line:

        thisQuery.Append(" SET " + fieldName + "=" + incrementedFieldValue.ToString());

It's referring to the incrementedFieldValue vairable, which is clearly defined at the top of the method and assigned a value in the switch statement.  What am I missing?

public static void IncrementFieldValue(string connectionString, string tableName, string fieldName, string condition, int incrementValue, string dataType)
    {
 
        int initialFieldValue;
        int incrementedFieldValue;
 
        switch (dataType)
        {
            case "int":
                initialFieldValue = GetDBIntFieldValue(connectionString, tableName, fieldName, "");
                incrementedFieldValue = initialFieldValue + Convert.ToInt32(incrementValue);
                break;
        }
 
 
        StringBuilder thisQuery = new StringBuilder();
        thisQuery.Append("UPDATE " + tableName);
        thisQuery.Append(" SET " + fieldName + "=" + incrementedFieldValue.ToString());
        if (condition.Length > 0)
            thisQuery.Append(" WHERE " + condition);
 
 
        SqlConnection thisConnection = new SqlConnection(connectionString);
        thisConnection.Open();
        SqlCommand thisCommand = new SqlCommand(thisQuery.ToString(), thisConnection);
        int returned = thisCommand.ExecuteNonQuery();
        thisConnection.Close();
 
 
    }

Open in new window

0
Comment
Question by:NigelRocks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 24020441
but in case your datatype is not INT, your variable remains unset. Initialize it when you declare it.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question