无效的对象名称

时间:2015-11-23 02:54:03

标签: c#

第一个是查询功能,通过使用VehicleNumber(tblDDDDriver中的字段或列名称之一)从表tblDDDDriver访问有关驱动程序的信息。 第二个是我编码访问该功能。 现在,当我点击按钮时,我显示错误无效的对象名称' tblDDDDriver'

public DataTable GetDriverByVehicalNumber(string VehicleNumber)
    {
        SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB; Integrated Security=True; Initial Catalog=tprojectDB;");
        string sql = "select *from tblDDDDriver where VehicleNumber=@VehicleNumber";
        SqlCommand cmd = new SqlCommand(sql, con);
        cmd.Parameters.AddWithValue("@VehicleNumber", VehicleNumber);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);

        return dt;
    }



 private void button6_Click(object sender, EventArgs e)
    {
        DataTable dt = dc.GetDriverByVehicalNumber(txtvehicleno.Text);
        if (dt.Rows.Count > 0)
        {
            txtlicenseno.Text = dt.Rows[0]["LicenseNumber"].ToString();
            txtlicensecategory.Text = dt.Rows[0]["LicenseCategory"].ToString();
            txtissuedate.Text = dt.Rows[0]["IssueDate"].ToString();
            txtrenewdate.Text = dt.Rows[0]["RenewDate"].ToString();
            txtfullname.Text = dt.Rows[0]["FullName"].ToString();
            txtdob.Text = dt.Rows[0]["DOB"].ToString();
            txtaddress.Text = dt.Rows[0]["Address"].ToString();
            string gender = dt.Rows[0]["Gender"].ToString();
            if (gender == "Male")
            {
                txtgender.Text = " MALE";
            }
            else
            {
                txtgender.Text = "FEMALE";
            }
            txtvehicleno.Text = dt.Rows[0]["VehicleNumber"].ToString();
            txthealthstaus.Text = dt.Rows[0]["HealthStatus"].ToString();
            txtdrivertype.Text = dt.Rows[0]["DriverType"].ToString();

            Image img;
            byte[] bytimg = (byte[])dt.Rows[0]["Image"];

            //convert byte of imagedate to Image format
            using (MemoryStream ms = new MemoryStream(bytimg, 0, bytimg.Length))
            {
                ms.Write(bytimg, 0, bytimg.Length);

                img = Image.FromStream(ms, true);

                pictureBox1.Image = img;
            }

        }
        DataTable dd = dc.GetMaxDeathNo(Convert.ToDecimal(txtlicensenumber.Text));
        if (dd.Rows.Count > 0)
        {
            txtdeathaccidentno.Text = dd.Rows[0]["DeathNumber"].ToString();
        }

        DataTable dM = dc.GetMaxMajorNo(Convert.ToDecimal(txtlicensenumber.Text));
        if (dM.Rows.Count > 0)
        {
            txtmajoraccidentno.Text = dM.Rows[0]["MajorNumber"].ToString();
        }

        DataTable dm = dc.GetMaxMinorNo(Convert.ToDecimal(txtlicensenumber.Text));
        if (dm.Rows.Count > 0)
        {
            txtminoraccidentno.Text = dm.Rows[0]["MinorNumber"].ToString();
        }

        DataTable dtrb = dc.GetTrafficRuleBroken(Convert.ToDecimal(txtlicensenumber.Text));
        {
            dataGridView1.DataSource = dtrb;
        }

    }

0 个答案:

没有答案