Home > database >  ") "near a syntax error. Description: during the execution of the current Web request, app
") "near a syntax error. Description: during the execution of the current Web request, app

Time:11-22

CodePudding user response:

SQLSTR print out and have a look

CodePudding user response:

This kind of writing, you can even use, also have SQL injection, can't reuse problem such as the execution plan,
Write a standard points:
 using System; 
Using System. The Data. SqlClient.

The namespace ConsoleApp18
{
/*
- build predicate sentence
The CREATE TABLE user_data (
UserId INT IDENTITY (1, 1) PRIMARY KEY,
The userName NVARCHAR (20) NOT NULL,
Birthday DATETIME NOT NULL
)
*/
Class Program
{
The static void Main (string [] args)
{
//1. The connection string, you according to your actual library, the user name password to
String connString="data source=(local); Initial catalog=tempdb for; Integrated Security=True ";
SQL statement
//2.String SQL="insert into user_data (userName, birthday) values (@ userName, @ birthday)";
The parameter//3.
SqlParameter spArr=new SqlParameter [] []
{
New SqlParameter (" @ the userName ", "Ming"),
New SqlParameter (" @ birthday, "DateTime. Parse (" 2008-09-30"))
};
//4. Actual execution
Try
{
Using (SqlConnection conn=new SqlConnection (connString))
{
conn.Open();
SqlCommand CMD=new SqlCommand (SQL, conn);
CMD. ExecuteNonQuery ();
}
Console. WriteLine (" execution success!" );
}
The catch (Exception ex)
{
Console. WriteLine (" failure!" + ex. Message);
}

The Console. The Read ();
}
}//end of the class
}//end of namespace

CodePudding user response:

You this is I've never used, how to use, copy and paste the whole?

CodePudding user response:

First create a console project, comprehend is what to do, learn, then it is ok to change my own project according to good,
  • Related