更新命令 [英] update command

查看:56
本文介绍了更新命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!!!
我有一个问题..我正在使用viaual Studio 2010,可以插入数据,但不能更新&删除.视觉工作室说此错误:索引"附近的语法不正确.如果要将其用作表提示的一部分,则现在需要A WITH关键字和括号.这是我用于UPDATE命令的代码:

hi!!!
i have a problem.. i am using viaual studio 2010 and i can insert data but i can''t UPDATE & DELETE. The visual studio says this error: Incorrect syntax near ''Index''. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. This is the code that i am using for the UPDATE command:

da.UpdateCommand = new SqlCommand("UPDATE Studenti SET  ime = @ime, prezime = @prezime WHERE Index = @Index",cs);
            da.UpdateCommand.Parameters.Add("@ime", SqlDbType.VarChar).Value = txtVnesiIme.Text;
            da.UpdateCommand.Parameters.Add("@prezime", SqlDbType.VarChar).Value = txtVnesiPrezime.Text;
            da.UpdateCommand.Parameters.Add("@Index", SqlDbType.Int).Value = ds.Tables[0].Rows[studentiBS.Position][0];
            cs.Open();
            da.UpdateCommand.ExecuteNonQuery();
           cs.Close();


我已经在网上搜索了,但找不到答案.请帮助


i have searched on the net but i cant find the answer. please help

推荐答案

zareppmk写道:
zareppmk wrote:

da.UpdateCommand.Parameters.Add( "@Index",SqlDbType.Int).Value = ds.Tables [0] .Rows [studentiBS.Position] [0];

da.UpdateCommand.Parameters.Add("@Index", SqlDbType.Int).Value = ds.Tables[0].Rows[studentiBS.Position][0];


错误就在这里.
您正在尝试将一个对象分配给int类型参数.

试试:


Error lies here.
You are tring to assign an object to int type parameter.

Try:

da.UpdateCommand.Parameters.Add("@Index", SqlDbType.Int).Value = Convert.ToInt32(ds.Tables[0].Rows[studentiBS.Position][0].ToString());


这篇关于更新命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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