How to manually add tables and values into SQL Server 2008

Discussion in 'Getting started' started by billy111, Oct 9, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hey,

    I am trying to add a table using SQL Server 2008, i have managed to do this, but can seem to work out how i can manually add rows into the database. I want to do a simple SELECT to ensure i can connect to the database so i need to enter some test information.

    Also I have tried inserting something into the database, and this does not work, i am using the following code:-

    PHP:
        protected void Button2_Click(object senderEventArgs e)
        {
            
    string conString "Data Source=tcp:esql2k801.discountasp.net;Initial Catalog=SQL2008_673062_kids;User ID=SQL2008_673062_kids_user;Password=********;";
            
    SqlConnection empConnection = new SqlConnection(conString);

            
    string insertStatement "INSERT INTO tbl_users " "([username], [password]) " "VALUES ('Test', 'Test')";

            
    SqlCommand insertCommand = new SqlCommand(insertStatementempConnection);

            
    empConnection.Open();

            try
            {
                
    int count insertCommand.ExecuteNonQuery(); 
            }
            catch (
    SqlException ex)
            {
                
            }
            finally
            {
                
    empConnection.Close();
            }
        }
    I think its the connection string thats is wrong, but need your adivce to help me out..

    Regards
     
  2. The code looks OK but if it's failing, it could be an incorrect connection string or maybe a few other things:
    1) The target db does not exist
    2) The target db does exist but the [tbl_users] table does not
    3) The values you're attempting to insert are of the wrong data type for the target table columns.

    If you can post the exception thrown, perhaps it will be a bit clearer.
     
  3. Joseph Jun

    Joseph Jun DiscountASP.NET Staff

    What error message is being thrown?
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page