System.Data.SqlClient.SqlException:'。'附近的语法不正确。
技术问答
169 人阅读
|
0 人回复
|
2023-09-12
|
我尝试一些有关.Net Core Wep API和SQL的知识。我在’。’‘附近有错误的语法。% l! q7 l! f' Q. G& [
谋使用邮递员的api并尝试与json一起来。8 u( P$ N9 o" U0 i5 Q. ^
在appsettings.json代码中;
5 `) C/ F9 x: V) N- w2 |+ }# b{1 A: R; c8 P. J, P
"ConnectionStrings": {! b b6 [" v- L# P
"EmployeeAppCon": "Data Source=.;Initial Catalog=EmployeeDB; Integrated Security=true"
% u. l5 d- n3 }( e) y },
9 |0 U8 d1 d$ j: _8 Q: e "Logging": {- G m/ f* Z1 X% P
"LogLevel": {6 g9 E: j8 K" N; z7 Z) `
"Default": "Information",; K( q; d$ p' j! {; t- F5 w
"Microsoft": "Warning",
9 u3 B2 Y1 I$ X3 e; v. |( c "Microsoft.Hosting.Lifetime": "Information"
, T% d2 A3 z* F, g% i2 }' p' r }4 w& l# N+ y1 b% F
},
! j: \ o3 B" H- o "AllowedHosts": "*"
7 r( [! c" s- i% _7 `$ o, a}
9 T2 n& R- ?1 H/ q谋杀尝试了get,post方法,但是谋杀了Uptade方法,这是一个错误;- }7 z) h% J- C4 V
[HttpPut]
: t; ^% v! `) S. P- o4 ?) E3 K6 C public JsonResult Put(Department dep)/ W! j7 c( J: P' i7 M% Z
{" D* k' l [8 R( p
string query = @"7 I' p9 R2 D4 E+ @' P
Uptade dbo.Department set ' E ^ ]# {2 N
DepartmentName='"+dep.DepartmentName+@"'
: n- {3 h5 ^, ` where DepartmentId="+dep.DepartmentId+@"9 \4 S6 `' }1 H! B6 O, p+ p- k/ y+ v
";2 P% S: q6 E: r% C+ {5 h* \
DataTable table = new DataTable();# t$ E& ~) S3 D' q% ?. u0 v0 _6 A
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
0 X+ @1 C# Z. F# B0 d2 |. q SqlDataReader myReader;3 S& G( u5 |& P" C
using (SqlConnection myCon = new SqlConnection(sqlDataSource))
' r, h; [+ |( G0 p, e ? {# e% B# n3 M2 R4 p9 c a
myCon.Open();' W/ O/ L+ L# U% U J
using (SqlCommand myCommand = new SqlCommand(query, myCon))
) n$ c! D: R: o `8 Y7 L% q {
9 U1 H# @0 l; j I3 } myReader = myCommand.ExecuteReader();
# f9 a- O# }% u% u3 _ table.Load(myReader); ;3 q- H+ Y" E8 }- W8 @
myReader.Close();
' ]1 ?2 ~4 Y0 t7 D myCon.Close();
1 v; [: j4 L! ^8 W: `9 s: Q }
o* Z' }1 g3 {- u( e }/ }# Y2 E' ^6 y2 E, W) E) Z
return new JsonResult("Uptade Successfull");
! d# S& n6 T; ]% V }7 B, D" M6 z7 \, F z1 {; Z" ? v
我的错在哪里,请多多帮助我。2 N% |0 d4 M; Y* g! t0 M
9 i- \/ N8 d, v
解决方案: |
|
|
|
|
|