在sqlserver 2008中写数据-如何在现有行中插入数据 [英] writing data in sqlserver 2008 - How to insert data in an existing row

查看:106
本文介绍了在sqlserver 2008中写数据-如何在现有行中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用参数

推荐答案

在现有行中插入数据这里是您可以阅读的一个很好的教程:SQL UPDATE语句 [ ^ ]

加法:

要基于列DateCol更新最后一行,该语句可能类似于:
Here''s one good tutorial you can go through: SQL UPDATE Statement[^]

Addition:

To update the last row based on column DateCol the statement could be something like:
UPDATE table 
SET ColumnA = @_ColumnA 
WHERE firstname LIKE @_firstname
AND DateCol = (SELECT MAX(DateCol)
               FROM table
               WHERE firstname LIKE @_firstname)


使用参数
将数据插入到现有行中 好像您要求基于参数的数据插入/更新.

在此处查找参数化查询及其用法:
MSDN:配置参数和参数数据类型(ADO.NET) [ MSDN:DataAdapter参数(ADO.NET) [ MSDN:SqlCommand.Parameters属性 [ SQL注入缓解:使用参数化查询 [
insert data in an existing row using parameter
Looks like you asked for parameter based data insert/update.

Look here for parameterized query and it''s usage:
MSDN: Configuring Parameters and Parameter Data Types (ADO.NET)[^]
MSDN: DataAdapter Parameters (ADO.NET)[^]
MSDN: SqlCommand.Parameters Property [^]


Read about protecting from SQL Injection here: SQL Injection Mitigation: Using Parameterized Queries[^]


与插入新行相同,只是使用UPDATE而不是INSERT.确保使用主键标识要更改的行.
Same as inserting new row, just use UPDATE instead of INSERT. Make sure you use primary key to identify the row you want to change.


这篇关于在sqlserver 2008中写数据-如何在现有行中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆