我想从数据库中获取第一行第一个单元格值,它可以很好地使用下面的代码.但是当没有找到结果时,它会抛出异常.
如何处理DBNull.
我应该更改我的查询吗?如果他们没有记录,哪些值会返回?
System.NullReferenceException:未将对象引用设置为对象的实例.
码:
public string absentDayNo(DateTime sdate, DateTime edate, string idemp)
{
string result="0";
string myQuery="select COUNT(idemp_atd) absentDayNo from td_atd where ";
myQuery +=" absentdate_atd between '"+sdate+"' and '"+edate+" ";
myQuery +=" and idemp_atd='"+idemp+"' group by idemp_atd ";
SqlCommand cmd = new SqlCommand(myQuery, conn);
conn.Open();
//System.NullReferenceException occurs when their is no data/result
string getValue = cmd.ExecuteScalar().ToString();
if (getValue != null)
{
result = getValue.ToString();
}
conn.Close();
return result;
}
Run Code Online (Sandbox Code Playgroud) 我想知道哪一个具有更好的返回性能DataTable.SqlDataReader我在这里使用DataTable.Load(dr)
使用SqlDataReader:
public static DataTable populateUsingDataReader(string myQuery)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(constring))
{
SqlCommand cmd = new SqlCommand(myQuery, con);
con.Open();
SqlDataReader dr = null;
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.HasRows)
{
dt.Load(dr);
}
return dt;
}
}
Run Code Online (Sandbox Code Playgroud)
使用SqlDataAdapter:
public DataTable populateUsingDataAdapter(string myQuery)
{
SqlDataAdapter dap = new SqlDataAdapter(myQuery,cn);
DataSet ds = new DataSet();
dap.Fill(ds);
return ds.Tables[0];
}
Run Code Online (Sandbox Code Playgroud) 我想Open File在我的网页上的链接上有一个对话框.
我试过了
<input name="uploadedfile" type="file">
Run Code Online (Sandbox Code Playgroud)
但是,它可以作为一个按钮.并且,不允许选择多个文件.
我希望有类似的东西
<a href="#" onclick="some_function_for_OpenFileDialogBox">Upload Files</a>
Run Code Online (Sandbox Code Playgroud)
请建议.
谢谢
考尔
在我的Asp.net应用程序中,我有一个GridView和我column[6]自己使用代码生成数据.
通过查看下面的代码,我有一个footer为我的gridview.如果我使用页脚,问题是列[6]的文本将不会出现.如果我删除了footertext代码,那么我的第[6]栏的文本就出现了.问题是什么?两个代码都不能使用togather?我已经设置了ShowFooter ="True"
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < (this.GridView1.Rows.Count); i++)
{
this.GridView1.Rows[i].Cells[6].Text = "testing";
//GridView1.Columns[1].FooterText ="footer 1";
}
}
Run Code Online (Sandbox Code Playgroud)
的.aspx
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False" DataKeyNames="ID" CellPadding="4"
ForeColor="#333333" GridLines="None" ShowFooter="True"
onrowdatabound="GridView1_RowDataBound">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="reportDate" HeaderText="Report Date" dataformatstring="{0:dd MMMM yyyy}" SortExpression="reportDate" />
<asp:BoundField DataField="sponsorBonus" HeaderText="Sponsor Bonus" dataformatstring="{0:0.00}" SortExpression="sponsorBonus" HtmlEncode="False" />
<asp:BoundField DataField="pairingBonus" HeaderText="Pairing Bonus" HtmlEncode="False" SortExpression="pairingBonus" dataformatstring="{0:c}" />
<asp:BoundField DataField="staticBonus" HeaderText="Static …Run Code Online (Sandbox Code Playgroud) 我从nodejs.org安装了node-v0.10.13-x86.msi
我有一个文件test.js有路径(d:\ BNB\test.js)
test.js:
console.log("Hello world!");
Run Code Online (Sandbox Code Playgroud)
我可以从我的cmd运行test.js但不能从node.js命令提示符下面参见截图
从开始>运行> cmd(工作)
从Node.exe(不工作)

我在asp.net mvc 2上有一个应用程序,它在我的电脑上的IIS 7.5上我尝试分析它,我注意到Application_Start 不止一次被调用,
任何人都知道为什么会发生这种情况?
我执行它时有一个存储过程我遇到了错误
将varchar值'+ @ dptId +'转换为数据类型int时转换失败
我得到DepartmentId一个像字符串,(1,3,5,77)并将其传递给我的存储过程.
create table dummy (id int,name varchar(100),DateJoining Datetime, departmentIt int)
insert into dummy values (1,'John','2012-06-01 09:55:57.257',1);
insert into dummy values(2,'Amit','2013-06-01 09:55:57.257',2);
insert into dummy values(3,'Naval','2012-05-01 09:55:57.257',3);
insert into dummy values(4,'Pamela','2012-06-01 09:55:57.257',4);
insert into dummy values(5,'Andrea','2012-09-01 09:55:57.257',3);
insert into dummy values(6,'Vicky','2012-04-01 09:55:57.257',4);
insert into dummy values(7,'Billa','2012-02-01 09:55:57.257',4);
insert into dummy values(8,'Reza','2012-04-01 09:55:57.257',3);
insert into dummy values (9,'Jacob','2011-05-01 09:55:57.257',5);
Run Code Online (Sandbox Code Playgroud)
查询我尝试过:
declare @startdate1 varchar(100) ='20120201'
declare @enddate1 varchar(100)='20130601'
declare @dptId varchar(100)='3,4'
select …Run Code Online (Sandbox Code Playgroud) 当我登录时,我将我的用户名存储在会话中.我的要求是我想将我的用户名存储在我的数据库中.我在这里存储它username1.输入用户名后,我可以使用response.write()它打印并完美打印.但是,当我将它存储在数据库中时,它会产生以下错误:
**sqlException was unhandled by user code and exception at cmd.ExecuteScalar(); String or binary data would be truncated. The statement has been terminated.**
以下是我的ado.net代码:
using (SqlConnection con =
new SqlConnection("Data Source=.;database=testdb1;Integrated Security=SSPI")) {
con.Open();
// SqlCommand cmd = new SqlCommand("delete from fileinfo where ID=" + Convert.ToInt32(Request.Params["one"]), con);
string uname = (string) Session["fname"].ToString() + " " + Session["lname"].ToString(); //Session["fname"].ToString()+" "+Session["lname"].ToString();
// Response.Write(uname);
// uname = "sri hari";
uname = uname + " ";
string uname1 = uname; …Run Code Online (Sandbox Code Playgroud) 我创建了一个在30分钟后触发的函数,我想传递一些参数.我有一个库返回carHistory,我的电子表格从我调用库函数.
Library1.gs
function carHistory(number,maker)
{
// code logic
}
function startEvery30mins_CarHistory(number,maker)
{
//This function works
carHistory(number,maker);
// how to trigger this with parameter.
ScriptApp.newTrigger("carHistory")
.timeBased()
.everyMinutes(30)
.create();
}
Run Code Online (Sandbox Code Playgroud)
在我的SpreadSheet中
Code.gs:
function startOnce(){
Library1.carHistory("US-xxx","Honda");
}
function startEvery30mins(){
Library1.startEvery30mins_CarHistory("US-xxx","Honda");
}
Run Code Online (Sandbox Code Playgroud)
编辑:
Code.gs:我尝试使用PropertiesService,但仍然无法正常工作
function startOnce(){
var uProps = PropertiesService.getUserProperties();
uProps.setProperty('Maker', 'Honda');
uProps.setProperty('Number', 'US-xxx');
Library1.carHistory();
}
Run Code Online (Sandbox Code Playgroud)
图书馆 :
function carHistory()
{
// Fetch Parametr
var getProps=PropertiesService.getUserProperties();
var c_Maker= getProps.getProperty('Maker');
var c_Number=getProps.getProperty('Number');
// code logic
}
Run Code Online (Sandbox Code Playgroud)
function startEvery30mins_CarHistory()
{
ScriptApp.newTrigger("carHistory")
.timeBased()
.everyMinutes(30) …Run Code Online (Sandbox Code Playgroud) 我对css3动画有一些奇怪的问题.
我有块元素与css3 transformation应用.当使用-webkit-transform矩阵应用转换时 - 元素看起来非常平滑.但是当我尝试使用-webkit-keyframes应用动画时,字体和其他一些div在动画期间看起来很糟糕.
样本可以在这里找到:http://shuma.ru/animation.html
问题可以在'webkit浏览器Safari/Chrome'等中看到.
asp.net ×4
c# ×4
ado.net ×1
asp.net-mvc ×1
css3 ×1
database ×1
datatable ×1
footer ×1
gridview ×1
html ×1
html5 ×1
iis ×1
iis-7 ×1
javascript ×1
node.js ×1
performance ×1
sql ×1
sql-server ×1
webkit ×1
windows ×1