使用csharp将记录从数据网格视图保存到数据库中 [英] Saving the record into database from data grid view using csharp

查看:122
本文介绍了使用csharp将记录从数据网格视图保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将记录从数据网格视图保存到数据库中。



代码如下;



Saving the record into data base from data grid view.

code as follows;

sql = "insert into Tb_SCh_TIme_Table(Date,Session,Course,Faculty_Code)" + " values ('" + Convert.ToDateTime(datagridView.Rows[i].Cells[0].Value.ToString()) + "', '" + int.Parse(datagridView.Rows[i].Cells[1].Value.ToString()) + "', '" + datagridView[j, i].Value.ToString() + "','" + datagridView.Columns[j].HeaderText.ToString() + "')";



通过以上查询保存到数据库。



数据库日期以1/7/2013 12:00:00 AM的格式存储。



但我希望日期以1月1日的格式存储只有。



以上格式的日期和月份(月份为字符格式)



转换。 ToDateTime(datagridView.Rows [i] .Cells [0] .Value.ToString()



来自上面的查询怎么办。



输出如下;



日期

1 jan

8 jan

2月2月



就像保存在数据库中一样。



怎么办。请帮助我。


through the above query it is saving to the data base.

in database Date is stored in the format such as 1/7/2013 12:00:00 AM.

but i want the the date to be stored in the format of 1 jan only.

the above format of date and month(Month to be character format)

Convert.ToDateTime(datagridView.Rows[i].Cells[0].Value.ToString()

from the above query how to do.

output as follows;

Date
1 jan
8 jan
3 Feb

like that to be saved in the data base.

how to do.please help me.

推荐答案

你无法控制Date存储在数据库中的方式。相反,在检索时你可以按照你想要的方式格式化它显示在前端。
You cannot control the way Date is stored in database. Instead while retrieving you can format it the way you want and display in front end.


这篇关于使用csharp将记录从数据网格视图保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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