将gridview selected.row.cells转换为sql [英] gridview selected.row.cells into sql

查看:161
本文介绍了将gridview selected.row.cells转换为sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从选定的单元格中获取数据并插入到sql表中

I am trying to get data from selected cells and insert into sql table

SqlCommand cmd = new SqlCommand("set identity_insert posudbe on INSERT INTO Posudbe (datumPosudbe,idClana,idNaslova) VALUES (@datumPosudbe,@idClana,@idNaslova) set identity_insert posudbe off", conn);
       cmd.Parameters.Add("@idClana", SqlDbType.Int).Value = gvClanovi.SelectedRow.Cells[0].Text;



收到此错误:



Get this error:

Failed to convert parameter value from a String to a Int32

推荐答案

使用以下方法解决:SelectedDataKey.Value.ToString()

可以了!

Resolved using this: SelectedDataKey.Value.ToString()

It''s working!

cmd.Parameters.Add("@idClana", SqlDbType.Int).Value = gvClanovi.SelectedDataKey.Value.ToString();


尝试:
cmd.Parameters.Add("@idClana", SqlDbType.Int).Value = int.Parse(gvClanovi.SelectedRow.Cells[0].Text);


您的字符串包含除Integer以外的其他字符,这就是您收到该错误的原因.确保该参数是Integer友好的.
Your string contains characters other than an Integer thats why your getting that error. Make sure that the parameter is Integer friendly.


这篇关于将gridview selected.row.cells转换为sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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