为什么我会发现这个错误 [英] Why i grt this error

查看:98
本文介绍了为什么我会发现这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DataTable dt = new DataTable();

DateTime time = DateTime.Now.AddHours(10.30);

dt = DAL.Registration_Master.View(time)。 ToString(); //错误





//错误无法将类型''string''隐式转换为''System.Data。 DataTable''



//这是什么解决方案?



即使我将其转换为



dt = Convert.ToDateTime(DAL.Registration_Master.View(time).ToString());



但它仍然给我错误..

DataTable dt = new DataTable();
DateTime time = DateTime.Now.AddHours(10.30);
dt =DAL.Registration_Master.View(time).ToString();//error


//Error Cannot implicitly convert type ''string'' to ''System.Data.DataTable''

//What is the solution for that?

Even when i convert it like

dt =Convert.ToDateTime(DAL.Registration_Master.View(time).ToString());

but still it gives me error..

推荐答案

您正在尝试将字符串值分配给DataTable。

You are trying to assign String value to DataTable.
dt =Convert.ToDateTime(DAL.Registration_Master.View(time).ToString());



您不能直接将字符串值分配给DataTable。


You cannot directly assign string value to DataTable.


您可以在创建列后将值分配给数据表。

我想,您可能需要代码像这样

you can assign the values to data table after creating columns into it.
I guess, you may want code like this
string dtt = DAL.Registration_Master.View(time).ToString();
DataTable dt = new DataTable();
DataColumn dc = new DataColumn();
dc.ColumnName = "Date";
dt.Columns.Add(dc);
dt.Rows.Add(dtt);





--Sj



--Sj


这篇关于为什么我会发现这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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