Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster
char letter = Char.Parse("a");
char letterEnd = Char.Parse("z");
if (File.Exists(dupePathDir))
{
    newfile = fname + extension; // set newfile initial value to match original filename
    while (File.Exists(newfile)) // loop while newfile exists in directory
    {
        for (char i = letter; i < letterEnd; i++)
        {
            int appended = fname.IndexOf("_" + i.ToString()); // obtain first indexed position of _letter in the file name, gets -1 if none
            if ((appended != -1) //Determine if the file name contains "_a" or whichever letter is currently represented by variable "i"
            {
                fname = fname.remove(appended) + "_" + (i+1).ToString(); // remove current _letter and add next one up in it's place
                newfile = fname + extension; // add the extension and compare in (File.Exists(newfile)) to continue or break loop
            }
            else
            {
                fname = fname + "_" + i.ToString(); //add _letter
                newfile = fname + extension; // add the extension and compare in (File.Exists(newfile)) to continue or break loop
            }
        }
    }
}

I believe that this loop might better serve your needs. I assumed here that all of your specific variables have been declared elsewhere in your code (ie: fname, extension, etc).

Hope this helps, I really didn't take the time to set up a file reader and such to test it but the loop SHOULD get you to the right place.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

I don't believe XNA 3.1 is supported by VS 2010 at this time, in case you are interested in XNA development.

Not sure on the version but tools for XNA development are included in the VS Express for Windows Phone install package and are installed as Windows XNA Game Studio 4.0 so I would assume that some XNA is supported by VS2010 or it wouldn't be included in the express edition.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

What you might want to consider is the following:

Disable the X close option for form 2 and instead put a button within the form that will perform the tasks of re-showing the first form and closing the 2nd.

Alternately, the FormClosing event SHOULD catch the close of the form and allow you to use the event handler to re-display the prior form with the possible exception being if the form you are closing is a modal dialog box as this is not disposed when the close is clicked but rather rendered hidden.

While I'm sure you've read it already this page has some resource information on the use of the formclosing event that may or may not help.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

I doubt that's what he wants to be honest. But even so he would have to re-open the initial base stream every call, or, perform a seek to the beginning of the file.

Actually, re-reading the original post...

It looks more like he wants to do the following:

Open file in reader -> Pass to function

In function: read line 1 to variable -> read line 2 to variable -> read line 3 just to set position in file -> pass back out of function

outside function: continue from file position and perform further tasks.

So ya, looks like I completely butchered it hehe... That's what I get for being over-tired and under-rested :yawn:

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Your update statement is wrong. you can't update SerialNo from this query.....

Any chance you could provide some code example for kayfar so they can see what would correct it?

As for me, I'm going to sleep :zzz:

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Maybe I just wasn't clarifying what I was trying to say (I've been awake way too many hours the past few days)...

Basically my interpretation of the problem was that the process in the first code segment was being called more than once and... when called the first time, worked as intended. When called subsequent times, it was intended to replicate the results of the first call but didn't.

My read into the cause of this is that the streamreader for the enclosed loop never closes and never resets to line 0 of the stream so in subsequent calls it basically does the following:

First call (line 0, 1, 2)
Second call (line 3, 4, 5)

and so forth.

I could be interpreting the situation completely incorrectly tho.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Ok, now that we've got an error message result...

Read this thread that might help resolve your issue

My first guess based on the above thread and the error you posted is a mis-match between the data types you are trying to insert and the data type of the column in the access database OR that you've used a reserved word in the definition of one of your columns.

Beyond that, I'll let the Access experts around here troubleshoot going forward :) but at least we have some errors to work with now.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Kayfar...

1) Did you change the code to

catch (Exception ex)
{
    ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('" + ex.ToString() + "');</script>");
}

2) with this code in place, not your original code of

catch (Exception)
{
    ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Fail to Updated!');</script>");
}

I want you to run your app in the browser.

Instead of receiving "Failed to Update!" you should receive a different message that represents the error that the application is encountering when it fails.

This error is what we need to see.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Glad I could help :) Don't forget to mark solved so others don't think the issue is still unresolved.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Right, I didn't solve the problem with my suggestion above but...

it should be telling you the exception that is being thrown in the pop-up and what I'm asking you to do is to write that exception in this thread so we (the rest of us who've been trying to help you troubleshoot) can see what error you are getting.

This will help us to figure out what specifically is malfunctioning in your code and help us better solve your issue for you.

So... When the pop-up comes up (using the code modification I gave you in THIS thread above) please write down or copy or whatever the error message it shows and paste it in this thread.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

My suggestion, enclose the process that you're using to populate the gridview in the following construct:

if (!Page.IsPostBack)
{
    GridViewPopulation();
}

Replace "GridViewPopulation()" with a procedure for populating your GridView control and it should only load on the initial page load and not on a postback event, hopefully preserving your GridView content.

Hope this helps :) Mark as solved if it resolves your issue.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Another resource to look at (if you haven't already) is at this page.

Shows the use of the InternetExplorer object class which has adjustable properties including height and width.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Yes and no... You're working on a windows application but you're calling your process in a browser which is why I figure that this *might* just work. Couldn't hurt to give it a try, no? :P

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Try the code sample at this page as it seems to do exactly what you want.

Seems to be a combination of C# and JavaScript coding to accomplish the effect.

Hope this helps :) Mark as solved if it does.

Edit: As a side note, the above sample appears to be for a web-app deployment, if you're working on a windows forms app then the sample may not work the same in a non-browser environment.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Wow... really? Your other post was already moved over here by a moderator, you've already had people working on your code for days now... duplicating this thread seems a bit redundant :)

That being said try changing

catch (Exception)
{
    ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Fail to Updated!');</script>");
}

to this

catch (Exception ex)
{
    ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('" + ex.ToString() + "');</script>");
}

This should give the exception detail that generates your problem instead of just "Fail to Updated". Once you have the actual exception detail post it here so we can see what, specifically, is generating your problem. ((As we've asked you to do in various ways for 2 days now in your original thread))

Thanks again :)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Hmm... Now I'm confused lol... and the difficulty is that you declare the reader within the 2nd function so it can't be managed from outside that function.

What I might recommend is that you take

TextReader read = new StreamReader(fin);

and declare it just below the fin stream instead of inside it's function. Then change the process for the 2nd read to read

public void setBionic ()
    {
        name = read.ReadLine();
        Aname = read.ReadLine();
        string hold = read.ReadLine();
    }

Also, what are you doing with "string hold"? because it's declared in the function but never used and the function is set to return "void" so "hold" seems to be redundant unless it's just a placeholder to cause a 3rd ReadLine.

In the end the new code segment to match your top segment would be:

Stream fin = File.Open("Bionics.txt", FileMode.Open);
TextReader file = new StreamReader(fin);
TextReader read = new StreamReader(fin);

for (int ct = 0; ct < 4; ct++)
{
    metal[ct].setBionic(fin);
}

read.Close();
fin.Close();

Of course, now I'm thoroughly confused however as to why you have a need for 2 readers for the same file... unless you have multiple calls to multiple files being handled with the 2nd process there.

The problem is that the 2nd reader is being called repetatively within a loop from the first function without ever closing afterward. Alternately if you need the 2nd reader's properties (fin) to be determined dynamically from outside the property you could still declare the reader …

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

While I'm seeing the close of the "fin" stream I'm not seeing the close of the "read" stream.

My guess here is that it may be possible that your "read" stream is picking up where it left off instead of starting at the top of the stream again when called subsequent to the first pass.

I could be wrong though :)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

I tried to duplicate this with Fireworks CS4 to see if I could find a solution for you.

What I did was typed some text onto a blank frame in Fw to see what was available for styles.

Without doing anything additional I had 0 styles available in the properties of the text and no immediately visible styles in the Styles picker under "Current Document".

However, there were still the adobe provided styles in the Styles picker if I changed it from "Current Document" to one of the built in style libraries and once a style was selected from there it was imported into the current document list and added to the style dropdown for the text properties as well.

My thought here, and I'm only guessing at this stage, is that you may need to either import a custom style library or you may have somehow damaged your adobe provided style libraries and may need to re-install them. Either that, or you just have no styles previously used in your document and need to import them.

Otherwise I'm not seeing any reason why Fw would refuse to allow a style modification to text based on what the CS4 version does for me (again, I'm not using same version as you I don't think).

In CS4 Ctrl-F11 opens the styles window where you can select from the pre-built styles or import new libraries so dunno if that'll help for you or not.

Hope …

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

A couple of things are bothering me about the code above from what I'm reading.

  1. the form tag only encompasses the submit button
  2. the only asp compatible element in the page is the submit button

While you have set the cmd.Parameters to pull values from the various inputs on the page, I don't believe elements that are outside of the <form></form> constructs will be actively read by the C# code-behind.

I believe that, as much as you 'like' the way the page looks with the current layout, you may need to convert the inputs into proper asp inputs and enclose them within the form for this to work properly.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

While I don't believe the example you are attempting is possible (to my knowledge) as you can't determine a button based on it's position within a table (again, to my knowledge)...

I think you could probably get away with 1 event handler that assigns different events based on which button calls it.

Realistically it would be better all around to have separate event handlers if you're going to be performing separate tasks. However, if your tasks are generally identical with minor differences (ie: a different variable value) depending on which button is pressed you could use the following to achieve this:

In the .aspx page my example uses this ~

<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="btn_onclick" />
        <asp:Button ID="Button2" runat="server" Text="Button" onclick="btn_onclick" />
        <asp:Button ID="Button3" runat="server" Text="Button" onclick="btn_onclick" />
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>

And in the code-behind it uses this ~

protected void btn_onclick(object sender, EventArgs e)
    {
        if (sender.Equals(Button1))
        {
            TextBox1.Text = "Button1";
        }
        else if (sender.Equals(Button2))
        {
            TextBox1.Text = "Button2";
        }
        else if (sender.Equals(Button3))
        {
            TextBox1.Text = "Button3";
        }
    }

The result is that the btn_onclick checks the sender against the various buttons until it finds a match and performs it's task based on that.

Hope this helps :) Please mark as solved if this resolves your issue.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Generally I don't get a lot of opportunity to work with filestream type controls because lately I've been doing more ASP.Net than straight up C# coding.

I did, however, find this forum post elsewhere that seems to cover much of the same issue you're asking about and seems to have come to some roundabout answers that might solve your problem.

Hope it helps :)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

I'm sorry, I did my best to wade through your code but I'm not much on VB. Hopefully someone with more in-depth knowledge of VB and SessionStates will be able to toss back an answer on this one for you.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Excellent!! Please remember to mark solved problems as solved to close the thread :)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Sorry, was trying to do what I could with what was provided but did you look into adatapost's suggestion at all? I had completely forgotten about that option when I was posting my original reply :)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

well the thing there is if you're using <asp:Hyperlink> that's almost identical to the <a href="" id="urlID"> example I was giving.

you can leave the format as:

<asp:HyperLink ID="eventLink" NavigateUrl="" runat="server">Calendar</asp:HyperLink>

and your code-behind would look like

eventLink.NavigateURL = "default.aspx?id.....";

In this way your URL component of the <asp:HyperLink> is determined at the code-behind level.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Actually...

I just found a MUCH simpler and neater solution for you :)

for your static URLs:

<a href="" id="url1" runat="server">test1</a>

and in the code-behind:

url1.HRef = "http://www.test.com";

You can declare an ID and runat environment into your <a> tags allowing you to dynamically set their properties in code-behind. So, essentially, you can declare your side-menu URLs at the same time you declare your in-content links and they will both contain the same information eliminating your problem entirely... unless I've lost track of what the problem was in the first place lol

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Generally I try to keep my responses as positive and helpful as possible. While I'm not always able to give an actual solution I try to do what I can or I don't normally post at all.

However, in the past 24 hours of thread skimming I've come across approximately 75% of the posts I've looked at where no reference code is provided. While not every question requires code examples in order to be resolved, many would strongly benefit from them.

What would probably help here would be code snippets from the areas of your application in which the affected control is in play. By seeing how it is currently being manipulated perhaps one of the many skilled and experienced coders on this site will be able to spot a flaw or loophole and provide a solution for you.

Again, I apologize if this sounds harsh and I'm not 100% directing it at you... you just happened to be the one poster at the end of a long list of several who didn't provide any objective code reference to work with :P

kvprajapati commented: Great Response!!! +10
Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Have you thought of making the myproj classes into subclasses of the tasklayer class set?

Doing something along the lines of:

public class _C : Tasklayer

An example of setting up inheritance can be found at THIS LINK.

Hope this helps solve your problem :) If it does, please mark thread as solved.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

I guess to start with...

What, if any, errors are you receiving when you attempt to run this code? This might help to narrow down the specific components of the code to look at.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Ok, well in that case...

If both the created links and the static links are within the same page environment...

You should be able to dynamically determine the static link values with some code-behind at the time of generation of the created links.

It would involve a bit more creative thought in the way you manage the links and may involve some variable placeholders within the code of the page itself (as opposed to the code-behind) but you should be able to get a generally working process going by using something like:

<a href="<%= urlVariableHere %>">

or similar. In this way you can set the required variable on the URL to match the values generated in your dynamic links.

That's just a first approximation thought on how to do it though.

Edit: Easy way to do this is to set up some Visible=false <asp:Label> on the page with their text components set to contain the generated URLs and use their labelName.Text property to populate the variable in the static URLs

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Nick,

Generally the installer for VS2010 will detect and upgrade all components as required in the conversion from 2005.

However...

If your local development machine is also running MS SQL Server 2005 and the install includes an upgrade to MS SQL Server 2008 you may run into some issues there. If MS SQL Server is actively running at the time of installation the install may fail and there is the slight possibility of damage to the MS SQL Server 2005 install.

If, on the other hand, your install does not include any change to MS SQL Server then you should have a relatively smooth upgrade even if you're installing the 2008 server management tools and such (which I believe are reverse-compatible with 2005 Server).

As for changes to your projects and code... The first time a project is opened within an upgraded environment (2005 project opened in 2010) it will prompt you to update the project.

If you are planning on working on the project in both versions do NOT do this as it will be unreadable in 2005 afterwards without some lengthy and annoying file tinkering.

I'm not sure about MS SourceSafe but I would personally think that if it was integrated into 2005 it would likewise be in 2010.

Hope this helps :)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Jesi,

Is the menu on the left side within the same frame/container as the other content or separated?

If it is separated you might be able to maintain the variables by declaring them outside of both containers and allowing access to them from either container. More or less setting them as global variables instead of local variables within the main container.

Without seeing actual coding references I wouldn't be able to be more specific in pinning down your issue at this point.

Hope this helps :) If it does, please mark as solved.

P.s.: this probably should have gone into the ASP.Net forum :P

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Ah, well that makes a lot more sense now hehe.

Anywho, glad you solved it, should still mark the thread as solved to keep people from thinking it's an active thread going forward from here.

3:21am = goodnight! :D

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

What, if any, errors are you getting back when you attempt to run the code? This would definitely help pinpoint the cause of the problem.

Alternately, what results are you getting and what results are you expecting?

And didn't I just reply to another question about how to take a radiobutton variable and put it into an Access Database? Seems like you're everywhere I turn tonight... stop following me!! ((sorry, it's late, really bad sense of humor mode activated))

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

I'm still curious where you're deriving the values that are being inserted based on the original code but I'm glad it was solved :)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

For starters I'm not sure about the INSERT statement you're using, also where is the information being derived from? Another table? An application?

Your use of:

INSERT INTO [TABLE] (Col1, Col2, Col3, Col4) SELECT '1', '2', '3', '4' ;

seems incorrect to my knowledge as I'd always known it as:

INSERT INTO [TABLE] {Col1,Col2,Col3,Col4} VALUES {Val1,Val2,Val3,Val4}

at that point you can declare the valuables to match your input requirements (whatever they may be).

If the values are being derived from an application source of some sort a basic loop on the application end would suffice to input your values to the DB, if they're being derived from another table then I'm not seeing where in your example you're collecting those values to assign to the new table.

If the values are derived from a 2nd table then you would probably use something more like this:

INSERT INTO [TABLE] {Col1,Col2,Col3,Col4} VALUES {SELECT Val1,Val2,Val3,Val4 FROM [TABLE2] WHERE row=counter}

assuming you have some sort of numerically indexed column in the 2nd table.

I, personally, if transferring data from table2 (or even tables 2,3,4 & 5) to table1 would likely invest the 5 minutes to create a simple win-forms app to do it and build the world's simplest data loop lol but that's me.

On re-reading your post though, are you trying to input just the values "1" "2" "3" and "4" into the 4 columns repeatedly without an external data source? If So, then:


       
Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Phil, if the issue has been resolved you may want to look into marking this thread as 'solved' so it doesn't look as though it's still an active thread ;) Glad you figured it out though.

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Check the MSDN site for details on configuring Microsoft products such as IIS.

Visual Studio suite configuration information is available at their site as well.

If you're familiar with VB or C# you should have minimal difficulty transitioning to ASP.Net coding as most of the code-behind involved is in either of those 2 languages. Some of the front end development is slightly different from developing for a windows forms application but not so much so that it'd be impossible to work through.

There are a number of excellent tutorial sites and information forums (such as this one) that can help you through the rough patches as you first get moving in the web application direction.

Hope that helps :)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

personally when populating from a dataset to any other type of container I use the following loop to ensure I get all the values. Since you didn't include any code to see what your current binding logic looks like I'll give an example below:

for (int a = 0; a < dataSetName.Tables["0"].Rows.Count; a++)
{
    DataRow dataRowName = dataSetName.Tables["0"].Rows[a];
    insert data item setup here
    dataListName.Items.Add(dataItemName);
}

Once the loop terminates all items from the original dataset table should be within the new datalist. If the list is only to be populated once then I would ensure that the procedure for this load is within a segment such as:

if (Page.IsPostBack == false)
{
    datalistGenerator();
}

Or... failing that, include a

dataListName.Items.Clear();

line pre-loading to ensure that you don't duplicate your entries.

Hope this helps, please mark solved if it does :)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

My eyes are burning lol.

I must've missed that step where you initialized login before, sorry.

Well, dude, I'm flat out of ideas.

I've never directly worked with remoting applications like you're doing here so I don't know if there are specific variables to the way this process works that are different between web and windows forms apps.

As I follow your code step by step it all appears fine, I'm not seeing any particular reason why it won't work.

The System.NullReferenceException you are getting indicates to me that you're calling on a variable that 'doesn't exist' somewhere but the point at which it gives it would narrow it down to either txtun.Text or your interface 'login.CheckUN()'. If it was the latter, I would assume the error message would indicate a specific position within the CheckUN procedure where it was running into an issue unless it was 'login' itself that was coming back null... WAIT!!!

#
ILogin login=null;
 
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
ChannelServices.RegisterChannel(new TcpChannel());
login=(ILogin)Activator.GetObject(typeof(LoginComponent.ILogin),"tcp://localhost:6392/theLogin");
}
catch(Exception ex)
{
lbls.Text=ex.ToString();
}

If you are using visual studio, set a breakpoint at the end of this segment and go into debug mode. I'm willing to bet that "login=(ILogin)Activator.GetObject(typeof(LoginComponent.ILogin),"tcp://localhost:6392/theLogin");" is your culprit right there as it's in a 'Try' block and if it fails leaves login = null. I'll even go so far as to narrow it down to just the ""tcp://localhost:6392/theLogin"" portion …

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

I just had a thought...

I've never used MarshalByRefObject so I'm not 100% on how it works. I'm assuming that your ILogin interface indirectly initializes your Login class through the statement

public class Login : MarshalByRefObject, ILogin

is this correct?

Because the only thing I can think of is that the Login class isn't initialized in the .cs file for the webform but I'm sure that it is or you'd be receiving some very angry errors from implementing

bool st=login.CheckUn(txtun.Text);

My assumption here (having not used MarshalByRefObject before) is that the call to

ILogin login=null;

works in a similar way to

Login myLogin = new Login()

Is that correct?

Now, your most recent post about the actual error message gets me thinking that the initialization issue might be in fact the case as the error indicates that you are pointing to a value that isn't initialized somewhere.

Based on the error segment it spat out:

Line 224: private void btnsign_Click(object sender, System.EventArgs e)
Line 225: {
Line 226: bool st=login.CheckUn(txtun.Text);
Line 227: }

It's indicating that one of 2 things (from what I can see) is not 'present' to the system. Those being login.CheckUN or txtun.Text. The issue could be that the .Text value for txtun is being lost somehow in the button click (unlikely since it would at the least provide a "" value) or that (as I theorized above) login is not initialized properly.

Sorry I got so …

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

Well I'm making the assumption that your DBConnector function is well formed as you didn't include any of it's code but...

Assuming that the db connection properties are well formed I'm not seeing any issues with your code off-hand.

An example of what I generally utilize in web-apps for DB connection would be:

blConn loadConn = new blConn(); //Represents separate class for DB connection strings to mask from primary class

    private bool checkUN(string userName)
    {
        string connStr = @loadConn.cString;
        SqlConnection loadMsgConn = new SqlConnection(@connStr);
        SqlCommand loadMsgCmd = new SqlCommand();
        loadMsgCmd = loadMsgConn.CreateCommand();
        loadMsgCmd.CommandText = @"select * from Customer_Details where cUser_Name='@un'");
        loadMsgCmd.Parameters.Add("@un", SqlDbType.VarChar);
        loadMsgCmd.Parameters["@un"].Value = userName;
        loadMsgConn.Open();
        int queryReply = loadMsgCmd.ExecuteNonQuery();
        bool respond = false;
        if (queryReply > 0)
        {
            respond = true;
        }
        return respond;
    }

Bear with my code as the names are from a cut'n'paste from a project I recently was working on. Essentially, assuming your SQL connection string is correctly set and you pass userName to the process it should return a bool reply based on a 0 or non-0 reply to the SQL query.

Alternately you can do this method:

blConn loadConn = new blConn(); //Represents separate class for DB connection strings to mask from primary class

    private bool checkUN(string userName)
    {
        bool respond = false;
        string connStr = @loadConn.cString;
        SqlConnection loadMsgConn = new SqlConnection(@connStr);
        SqlDataAdapter loadMsgAdapt = new SqlDataAdapter(@"select * from Customer_Details where cUser_Name='"+userName+"'", loadMsgConn);
        SqlCommandBuilder loadMsgBuilder = new SqlCommandBuilder(loadMsgAdapt);
        DataSet loadMsgSet = new DataSet();
        loadMsgAdapt.Fill(loadMsgSet, "unCheck");
        loadMsgConn.Close();
        if (loadMsgSet.Tables["unCheck"].Rows.Count > 0) …
Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

I could be wrong here but textun.Text would be a text box within the web form itself not a variable to be initialized.

The way I'm reading it he's passing the text value of a TextBox named "textun" to a process named "CheckUN" within class "login".

Beyond that, as I look through the code, I'm not seeing any reason (provided all the classes and interfaces are properly initialized) that you wouldn't be receiving a true/false response from your bool inquiry in the above code segments.

As a side note, your sql query to determine merely if there is or isn't a username that matches in the DB can be accomplished using ExecuteNonQuery() instead of using a reader since all you need to know is whether there are rows returned or not. ExecuteNonQuery() will return a numeric value only as an indication of affected rows so your code could be set to trigger on 0 or > 0 results instead. But that's just my thougt on the matter ;)

Lusiphur 185 Practically a Posting Shark Team Colleague Featured Poster

I was recently having the exact same problem with a listbox control on my site.

The problem, as it turns out, was that the information bindings were being constantly changed every time the page was loaded (postback or otherwise).

I believe that if you change it so that the actual databind process is accomplished within the vb equivalent of below, it might work out for you:

if (Page.IsPostBack == false)
{
    ...page's databind processes here...
}

For example on my site's journal view page my Page_Load segment looks like this:

protected void Page_Load(object sender, EventArgs e)
    {
        //Split query pos 1 = Post Number
        string getQuery = ClientQueryString; //obtain variables from passed link ?orig=#&resp=#
        string[] querySplit = getQuery.Split('=', '&');
        origNum = Convert.ToInt16(querySplit[1].ToString());
        listedPage.Text = Convert.ToString(origNum);
        if (Page.IsPostBack == false)
        {
            loadMessageList();
            loadRespList(origNum);
        }
        navButtonSetup();
        if (origNum != -1) //if passed replyID != -1 load passed ID
        {
            loadMessage(origNum);
        }
        else //if passed replyID == -1 load lowest ID
        {
            origNum = lowestPost;
            loadMessage(lowestPost);
            if (Page.IsPostBack == false)
            {
                loadRespList(lowestPost);
            }
            navButtonSetup();
        }
        if (listRespBox.Items.Count > 0)
        {
            listRespButton.Visible = true;
        }
    }

However if I did the loadRespList or loadMessageList segments outside of the if (Page.IsPostBack == false) constructs I would receive the same error you reported with your code.

I hope this helps! :D Mark as solved if it does.