Home > Net > C # realize the KTV, please point ge tais project how to do?
C # realize the KTV, please point ge tais project how to do?
Time:10-04
I college students, just contact learned Java programming based directly after the c # and the final project requirement with visual studio 2012 and SQL server2008 design a KTV ge tais project application form is not a problem is how to connect to the database functionality no clue, who can give me about ideas
"Finished" Java, now learning the.net/c # is not "how to connect to database", this should be the school didn't teach good, learn knowledge all forget,
CodePudding user response:
Falsehood, application form is not a problem, a connection database how also won't? Application form is much more complicated than the database manipulation,
CodePudding user response:
Connect to the database is the most simple c # console application:
using System; Using System. The Data. SqlClient.
The namespace ConsoleApp2 { Class Program { The static void Main (string [] args) { //VS access available connection string: https://blog.csdn.net/yenange/article/details/77026214 //connection string it ourselves String connString=@ "Data Source=(local) \ sqlserver2014; Initial Catalog=master; Integrated Security=True "; String SQL="select count (1) as the from CNT master. The dbo. Spt_values where [type]='P' and [number] & gt;=@ n "; Try { Using (SqlConnection conn=new SqlConnection (connString)) { Conn. The Open (); SqlCommand CMD=new SqlCommand (SQL, conn); CMD. The Parameters. AddWithValue (" @ "n", 0); Int CNT=the Convert. ToInt32 (CMD) ExecuteScalar ()); Console. WriteLine (" the count: {0} ", CNT); } } The catch (Exception ex) { Console. WriteLine (ex. Message); } The Console. The Read (); } } }
CodePudding user response:
There is a problem, the following code database connection is not closed? And catch the direct display an error message