CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2010
    Location
    .NET 4.0/VS2010
    Posts
    79

    Question Write to Sql DataBase

    hey all,

    i am working on an application that will help my band director with uniform check in and check out. i originally started this project in Visual Basic but found that C sharp was far better for doing this. i am pretty well done with the Check Out form for one ouniform but now i need to submit all the information i take in from the form to a database for saving. here is as far as i have gotten.
    Code:
                SqlConnection dataConnection = new SqlConnection();
                try
                {
                    dataConnection.ConnectionString = "Integrated Security=ture;" + "Initial Catalog=Band;" + "Data Source = TNIXON-PC-05\\Sitz.CheckInCheckOut";
    
    
                    dataConnection.Open();
    
                    SqlDataAdapter dataAdapter = data
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error accessing the database: " + e.Message);
                }
    this is all i have i cant understand how to really write to the database. i ahve a book for C sharp programming but i cant understand how to write the information to the database. please help?

    thanks in advance

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Write to Sql DataBase

    Search bing or google for "SqlConnection SqlDataAdapter writing to a database".

    You will be rewarded with mucho code samples.

  3. #3
    Join Date
    Jul 2010
    Location
    .NET 4.0/VS2010
    Posts
    79

    Re: Write to Sql DataBase

    okay i searched bing and i am working on this one tutorial that seems to have good information on it. i got this error that says my login failed. well i see why it didnt use my sql authentication that was meant to be used. how do i set the login to be SQL not Windows?

  4. #4
    Join Date
    Jul 2010
    Location
    .NET 4.0/VS2010
    Posts
    79

    Re: Write to Sql DataBase

    okay that tutorial showed me how to fix that error now i have error 0: saying that no process is on the other end of the pipe? what does that mean?

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Write to Sql DataBase

    What connection string are you using?

  6. #6
    Join Date
    Jul 2010
    Location
    .NET 4.0/VS2010
    Posts
    79

    Re: Write to Sql DataBase

    i am not sure. it started throwing error 26: again.
    here is the code used for the connection. it all happens when you click the CheckOut button

    Code:
            private void btnCheckOut_Click(object sender, EventArgs e)
            {
                SqlConnection dataConnection = new SqlConnection();
    
                dataConnection.ConnectionString = "user id=jsitz1469;" + "password=labR2o6;" + "Trusted_Connection=yes;" + "Data Source=TNIXON-PC-05\\SITZ;";
                    try
                    {
                        dataConnection.Open();
                    }
                    finally
                    {
                        dataConnection.Close();
                    }
            }
    what am i doing wrong? and how do i select the database i want to use. 'SITZ' is just the name of the Instance i need to select a particular database from within that instance.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Write to Sql DataBase

    Check out the following site for db connection strings:

    http://www.connectionstrings.com/

  8. #8
    Join Date
    Jul 2010
    Location
    .NET 4.0/VS2010
    Posts
    79

    Re: Write to Sql DataBase

    ahhhhhh i cant get it to connect now. i get error: 40 - could no open a conneciton to SQL Server


    here is the connection string
    Code:
     dataConnection.ConnectionString = "user id=jsitz1469;" + "password=labR2o6;" + "Data Source=TNIXON-PC-05\\SITZ;" + "Initial Catalog=CheckInCheckOut;" + "Integrated Security=true;";
    and i know i know dont hard code log in information into the application but i am working on getting connected before i start encrypting the information

  9. #9
    Join Date
    Dec 2007
    Posts
    234

    Re: Write to Sql DataBase

    You use a trusted connection OR login info (userID/password) ... but NOT both... if you are trying to use a SQL Login... drop the TrustedConnection=True from your connection string. By using it and setting it to True, you're saying that you want to use Windows Login.

    -tg
    * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help - how to remove eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
    * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
    MVP '06-'10

  10. #10
    Join Date
    Jul 2010
    Location
    .NET 4.0/VS2010
    Posts
    79

    Re: Write to Sql DataBase

    oh,
    that makes sense, thank you TechGnome. that allowed for my connection to become valid i think. it doesnt throw an error when i click the button associated with the connection. so i am assuming that the connection at this point is opened and then closed. now i need to write some string values to the database. this is the tricky part though isnt it?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured