gpt4 book ai didi

c# 对象引用未设置为对象的实例

转载 作者:行者123 更新时间:2023-11-30 22:21:42 25 4
gpt4 key购买 nike

<分区>

我正在从网站上执行约会功能。它可以在创建新约会之前比较日期和时间,如果数据库中存在相同日期和时间的用户键,它将弹出消息框。当我尝试插入与数据库不同的不同日期和时间时,它给我错误。 Error

我在这一行收到错误:

string dtime = time.ExecuteScalar().ToString();

我不知道我的代码有什么问题,有人能指出我吗?谢谢。这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Windows.Forms;
public partial class MakeAppointment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string appointmentdate = Convert.ToString(DropDownListDay.Text + "-" + DropDownListMonth.Text + "-" + DropDownListYear.Text);
string appointmenttime = Convert.ToString(DropDownListHour.Text + ":" + DropDownListMinute.Text + ":" + DropDownListSecond.Text + " " + DropDownListSession.Text);

SqlConnection con = new SqlConnection("Data Source=USER-PC;Initial Catalog=webservice_database;Integrated Security=True");
con.Open();
SqlCommand date = new SqlCommand("Select adate from customer_registration where adate='"+ appointmentdate +"'",con);
string ddate = date.ExecuteScalar().ToString();
con.Close();
if (ddate == appointmentdate)
{
con.Open();
SqlCommand time = new SqlCommand("Select atime from customer_registration where atime='"+ appointmenttime +"'", con);
string dtime = time.ExecuteScalar().ToString();
con.Close();

if (dtime == appointmenttime)
{
MessageBox.Show("This appointment is not available. Please choose other date & time.");
}
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com