问题描述
我有一张桌子,其中包含学生姓名学生标记学生成绩的字段
如果已经有一行 - >在那张桌子上
学生姓名 - 学生标记--- studentgrade
--- ram ----------- - 80 ------------ A -------
如果我想要通过更新学生标记来编辑这一行(现有学生标记+80 =新学生标记)然后该怎么办
我试过
更新studtable set studentmark = studentmark + 80,其中studentname = textbox1.text
我希望实现类似追加数据的功能到行中的现有数据:(
这不起作用:(我不知道为什么:(请帮帮我..或者任何人都可以告诉我是否使用更新sql中的where子句是错误的:
:(请帮我解决紧急问题:(
I have a table with contains the fields student name student marks student grade
If aldready there is a row -> in that table
Studentname -- studentmarks --- studentgrade
---ram ------------- 80 ------------ A-------
If i want to edit this row by updating the student mark as ( "existing student mark+80=new student mark") then what shall i do
I tried
Update studtable set studentmark=studentmark+80 where studentname=textbox1.text
I want to achieve something like appending data to existing data in the row :(
this is not working :( i dont know why :( please help me out ... or else can anyone tell me whether
using "where clause in Update sql is wrong :( please help me out urgent :(
推荐答案
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlConn; // already setup somewhere.
cmd.CommandType = CommandType.Text
cmd.CommandText = "Update studtable set studentmark=studentmark+80 where studentname=@studentName"
cmd.Parameters.AddWithValue("@studentName", textbox1.Text);
cmd.ExecuteNonQuery();
这篇关于将数据附加到sql server数据库中的现有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!