简单问题,望有人指点!

NO28 2004-11-16 04:17:33
SqlConnection MyConnection = new SqlConnection(@"server=127.0.0.1;uid=;………………);
string SqlUpdate = "Update Customers Set Country=@country,City=@city,…………)
其中@的作用是???
...全文
76 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
NO28 2004-11-17
  • 打赏
  • 举报
回复
谢谢指点~`,我有点懂了!
有没有关于C#与ASP.NET方面好的电子书介绍一下,或是发到我的email:no_28@126.com(支持30M附件)
thank you very much!
cdo 2004-11-16
  • 打赏
  • 举报
回复
@"dskjfkjdkjfdjk"这里的@表示""里面的全为字符串。

"@country"这里的@表示参数
Eddie005 2004-11-16
  • 打赏
  • 举报
回复
哦,忘了说这个了,在SqlConnection MyConnection = new SqlConnection(@"server=127.0.0.1;uid=;………………);这里的@就不是同一个东西了,

字符串为 string 类型并可写成两种形式,即用引号引起来和用 @ 引起来。用引号引起来的字符串括在双引号 (") 内:

"good morning" // a string literal
并且可以包含包括换码序列在内的任何字符:

string a = "\\\u0066\n"; // backslash, letter f, new line
注意 转义码 \udddd(其中 dddd 是一个四位数)表示 Unicode 字符 U+dddd。还可识别 8 位 Unicode 转义码:\udddd\udddd。
用 @ 引起来的字符串以 @ 开头,并用双引号引起来。例如:

@"good morning" // a string literal
用 @ 引起来的优点在于换码序列“不”被处理,这样就可以轻松写出字符串,例如一个完全限定的文件名:

@"c:\Docs\Source\a.txt" // rather than "c:\\Docs\\Source\\a.txt"
若要在一个用 @ 引起来的字符串中包括一个双引号,请使用两对双引号:

@"""Ahoy!"" cried the captain." // "Ahoy!" cried the captain.
@ 符号的另一种用法是使用碰巧成为 C# 关键字的被引用的 (/reference) 标识符。有关更多信息,请参见 2.4.2 标识符。

Eddie005 2004-11-16
  • 打赏
  • 举报
回复
当然你也可以直接写string SqlUpdate = "update customers set country='" + TextBox1.Text + "',city='beijing',.....";
但是这样一方面不容易阅读和调试,运行效率也不高(不肯定、如果我没记错的话)

使用存储过程也不一定要用它,string sqlUpdate = "dbo.preUpdate 'china','ciry',''....";也是可以运行的,看你自己喜欢啦...
NO28 2004-11-16
  • 打赏
  • 举报
回复
什么时候才要用到@啊
参数标记
SqlConnection MyConnection = new SqlConnection(@"server=127.0.0.1;uid=;………………);
string SqlUpdate = "Update Customers Set Country=@country,City=@city,…………)

System.Data.OleDb.OleDbCommand tmp = new System.Data.OleDb.OleDbCommand(SqlUpdate,MyConnection);
tmp.Parameters.Add("@country",System.Data.OleDb.OleDbType.VarChar,100);
tmp.Parameters["@country"].Value= "China";
有了它才能往Command对象里加入参数和参数的值
像这样用@一项一项加不是很麻烦?
能不能告诉我,什么时候才要这样用啊
Qinzijian 2004-11-16
  • 打赏
  • 举报
回复
我也是新手,路过看看。不知道下面的示例对你有没有帮助:

真实输出内容
string c = "hello \t world"; // hello world
string d = @"hello \t world"; // hello \t world
string e = "Joe said \"Hello\" to me"; // Joe said "Hello" to me
string f = @"Joe said ""Hello"" to me"; // Joe said "Hello" to me
string g = "\\\\server\\share\\file.txt"; // \\server\share\file.txt
string h = @"\\server\share\file.txt"; // \\server\share\file.txt
Eddie005 2004-11-16
  • 打赏
  • 举报
回复
参数标记
SqlConnection MyConnection = new SqlConnection(@"server=127.0.0.1;uid=;………………);
string SqlUpdate = "Update Customers Set Country=@country,City=@city,…………)

System.Data.OleDb.OleDbCommand tmp = new System.Data.OleDb.OleDbCommand(SqlUpdate,MyConnection);
tmp.Parameters.Add("@country",System.Data.OleDb.OleDbType.VarChar,100);
tmp.Parameters["@country"].Value= "China";
有了它才能往Command对象里加入参数和参数的值
NO28 2004-11-16
  • 打赏
  • 举报
回复
是不是与存储过程有关啊?
我不懂存储过程

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧