I am trying to develop a very simple Student Enrollment System, and as I built and compiled my solution, an ArgumentException was caught near my connection string. The exception message displayed is this:
Keyword not supported: '@datasource'.
I checked for inner exceptions and the exception details, but found nothing that can give me the slightest of hint about the reason behind this exception.
What am I doing wrong??? Is it syntactical error??? Or did I get my connection string wrong???? Can anyone point it out please????
Here's my code where the exception is getting caught:
#region Database Connection
public SimpleEnrollmentSystem()
{
InitializeComponent();
//creating a connection
connection = new SqlConnection();
command = connection.CreateCommand();
connection.ConnectionString = "@DataSource = SAADMAAN;" +
"Initial Catalog=db_student;User ID=sa;Password=***********";
updateReady = false;
insertReady = false;
}
#endregion
I also have a database named db_student in SQL Server 2012. The only table I have there is named Students, which is structured in the following way:
CREATE TABLE Students
(
StudentID int unique primary key,
FirstName varchar(50),
LastName varchar(50),
Gender varchar(10),
Age int,
Address varchar(MAX)
)
Note that I'm using Visual Studio 2012 and MS SQL Server 2012.
try:
connection.ConnectionString = @"Data Source = SAADMAAN;" +
"Initial Catalog=db_student;User ID=sa;Password=***********";
EDIT :
Be sure to leave a space beetween Data
and Source
and @
out of string literal
尝试使用:
connection = new SqlConnection("data source=SAADMAAN;initial catalog=db_student;User ID=sa;Password=***********");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.