Click here to Skip to main content
15,884,836 members
Home / Discussions / C#
   

C#

 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 8:17
bigjoe11a30-May-09 8:17 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 8:33
bigjoe11a30-May-09 8:33 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
Henry Minute30-May-09 8:59
Henry Minute30-May-09 8:59 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 9:08
bigjoe11a30-May-09 9:08 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
Henry Minute30-May-09 9:14
Henry Minute30-May-09 9:14 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
Henry Minute30-May-09 9:22
Henry Minute30-May-09 9:22 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 9:59
bigjoe11a30-May-09 9:59 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
Henry Minute30-May-09 10:43
Henry Minute30-May-09 10:43 
Apart from the fact that you execute the command twice:
MyCmd.ExecuteNonQuery();
Int32 rowsAffected = MyCmd.ExecuteNonQuery();


I could not see anything wrong with the code, as it is. So I copied and pasted it into a project. To get it to compile on my machine I changed all your calls to RMDoor.whatever to Console.whatever and commented out the savelog line. I created a new database, added a table called UserData with two columns Name and telnetaddr both nvarchar(50).

In the project I created a new DataSource ConsoleUsersTestDataSource from the database above, and ran the project.

Because the command executes twice, it added two new records, with identical data.

Just so that you can see that my code is essentially identical to yours, here it is:
class Program
{
    static void Main(string[] args)
    {
        add();
    }

    public static void add()
    {
        Console.Clear();

        Person addr = new Person();

        Console.Write("Enter Name : ");
        addr.name = Console.ReadLine();


        Console.Write("Address : ");
        addr.telnetaddr = Console.ReadLine();

        Console.Clear();

        Console.WriteLine("BBS Name : " + addr.name);
        Console.WriteLine("Telnet Address : " + addr.telnetaddr);
        Console.WriteLine();

        Console.Write("Is this what you want Y/N");
        string Q = Console.ReadLine();
        Q = Q.ToUpper();
        //savelog("User has just added an entry");
        if (Q == "Y")
        {
            string UserConnection = Properties.Settings.Default.ConsoleUsersTestConnectionString;
            SqlConnection MyConnection = new SqlConnection(UserConnection);

            String MyString = @"INSERT INTO UserData (Name, telnetaddr) VALUES('" + addr.name + "', '" + addr.telnetaddr + "')";
            SqlCommand MyCmd = new SqlCommand(MyString, MyConnection);

            MyConnection.Open();
            try
            {
                MyCmd.ExecuteNonQuery();
                Int32 rowsAffected = MyCmd.ExecuteNonQuery();
                Console.WriteLine("RowsAffected: " + rowsAffected);
                MyConnection.Close();
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }


        }
        else
        {
            Console.WriteLine("Save Aborted");

        }

        Console.WriteLine("Press Enter to Continue");
        Console.WriteLine();

    }
}


I can only suggest that you try cleaning your solution (Build | Clean Solution, just in case you don't know) and then rebuild it.

If it doesn't work then, I can only assume that there is something wrong with your database; or you have duplicate databases and that you are updating one of them and checking the other for changes, which obviously won't be there; or something really weird like that.

Apart from deleting the extra ExecuteNonQuery() line I am at a loss.

Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”

GeneralRe: SQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 11:31
bigjoe11a30-May-09 11:31 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
Henry Minute30-May-09 11:52
Henry Minute30-May-09 11:52 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 12:03
bigjoe11a30-May-09 12:03 
QuestionUpdating changings back to DB from DataGridView Pin
WinSolution30-May-09 3:11
WinSolution30-May-09 3:11 
AnswerRe: Updating changings back to DB from DataGridView Pin
Henry Minute30-May-09 4:12
Henry Minute30-May-09 4:12 
AnswerRe: Updating changings back to DB from DataGridView Pin
I Believe In GOD30-May-09 10:08
I Believe In GOD30-May-09 10:08 
GeneralRe: Updating changings back to DB from DataGridView Pin
Henry Minute30-May-09 10:51
Henry Minute30-May-09 10:51 
GeneralRe: Updating changings back to DB from DataGridView Pin
I Believe In GOD30-May-09 12:38
I Believe In GOD30-May-09 12:38 
GeneralRe: Updating changings back to DB from DataGridView Pin
WinSolution31-May-09 1:31
WinSolution31-May-09 1:31 
GeneralRe: Updating changings back to DB from DataGridView Pin
I Believe In GOD31-May-09 1:49
I Believe In GOD31-May-09 1:49 
QuestionGet the absolute pix of Html Element Using mshtml Pin
Member 437807730-May-09 3:00
Member 437807730-May-09 3:00 
QuestionPlease help Pin
Etienne_12330-May-09 1:57
Etienne_12330-May-09 1:57 
AnswerRe: Please help Pin
Henry Minute30-May-09 4:02
Henry Minute30-May-09 4:02 
AnswerRe: Please help Pin
I Believe In GOD30-May-09 10:11
I Believe In GOD30-May-09 10:11 
GeneralRe: Please help Pin
Etienne_12330-May-09 23:31
Etienne_12330-May-09 23:31 
GeneralRe: Please help Pin
I Believe In GOD31-May-09 1:54
I Believe In GOD31-May-09 1:54 
Questionservice of Events in C# [modified] Pin
arturw8230-May-09 1:40
arturw8230-May-09 1:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.