如何在asp.net mvc3中将字符串作为整数保存到数据库中 [英] how to save string into database as integer in asp.net mvc3

查看:104
本文介绍了如何在asp.net mvc3中将字符串作为整数保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在使用dropdownlist的过程中建立了网格,

如果我从下拉列表中选择任何项目,则应根据其ID将其保存为整数.


鉴于我已将其视为字符串

在模型中,我将其视为字符串

但在控制器查询中,我需要将其从字符串转换为短字符串"


例如:res.cat_id = c.category;

但我遇到错误,将其更改为整数,而我做错了,我无法理解.


请任何人给我样品或相关类型的解决方案.

谢谢,

解决方案

您需要使用Int32.Parse()Int32.TryParse()方法将字符串转换为整数.


Sukanya,尽管您应该在初始阶段就已经做好了DB设计的工作.但是到目前为止,如果您走得很远,我建议您从控制器转换为所需格式的所需数据,然后发送插入查询.

使用convert.toint和.tostring()将数据转换为所需的格式.


hi
i have build grid in that i am using dropdownlist

if i select any item from dropdownlist it should be save to database as intger according to it''s Id.


In view i had taken it as string

in model i had taken it as string

but in controller query i need to convert it from "string to short"


ex: res.cat_id = c.category;

but i am getting error that change it to string to integer where i am doing wrong i couldn''t able to understand.


please any one give me sample or related type solution.

Thank you,

解决方案

You need to use the Int32.Parse() or Int32.TryParse() method, to convert from string to integer.


Sukanya, though you should have had taken care of DB design in the initial stage. but as of now if you have gone very far I would suggest you to convert the required data in required format from controller and then send the insert query.

use convert.toint and .tostring() to convert the data into ur desired format.


这篇关于如何在asp.net mvc3中将字符串作为整数保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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