-
October 26th, 2010, 08:50 AM
#1
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
-
October 26th, 2010, 02:06 PM
#2
Re: Write to Sql DataBase
Search bing or google for "SqlConnection SqlDataAdapter writing to a database".
You will be rewarded with mucho code samples.
-
November 1st, 2010, 01:07 PM
#3
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?
-
November 1st, 2010, 01:09 PM
#4
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?
-
November 1st, 2010, 01:48 PM
#5
Re: Write to Sql DataBase
What connection string are you using?
-
November 2nd, 2010, 09:56 AM
#6
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.
-
November 2nd, 2010, 10:54 AM
#7
Re: Write to Sql DataBase
Check out the following site for db connection strings:
http://www.connectionstrings.com/
-
November 4th, 2010, 08:52 AM
#8
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
-
November 4th, 2010, 11:08 AM
#9
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
-
November 5th, 2010, 12:25 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|