当我运行以下代码时,我遇到了错误 [英] I Have Following Error When I M Runnning Following Code

查看:65
本文介绍了当我运行以下代码时,我遇到了错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Leptonlibrary;
using System.Collections;

namespace AddressExtractor
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            LeptonDataLayer.MySqlConnectionString = "server=192.168.1.224; user id=root; password=lepton; database=leptondata; pooling=false;default command timeout=3600;";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }




private void button1_Click(object sender, EventArgs e)
       {




if (txtUserName.Text == "")
           {
             MessageBox.Show("Please Enter UserName");
             txtUserName.Focus();
             return;
           }
           if (txtPassword.Text == "")
           {
               MessageBox.Show("Please Enter Password");
               txtPassword.Focus();
               return;
           }
           if (ddlCityName.Text != "")
           {
               this.Hide();
               Form1 frmmain = new Form1();
               frmmain.UserName = txtUserName.Text;
               frmmain.CityName = ddlCityName.Text;
               string cityname = frmmain.CityName;
               string newcituname = string.Empty;
               newcituname = cityname;
               frmmain.NewCityName = newcituname;




string SqlQuery = "Update " + frmmain.CityName + " set  assignedtouserid='" + frmmain.UserName + "', flag=1 where flag=0 and city like '%" + newcituname + "%' ORDER BY LOCALITY DESC limit 100 ";
                LeptonDataLayer.ExecuteNoneQuery(1, SqlQuery);
                SqlQuery = "Update userlogin set  LoginDateTime=NOW() where UserName='" + frmmain.UserName + "'";
                LeptonDataLayer.ExecuteNoneQuery(1, SqlQuery);
                frmmain.ShowDialog();

            }
            else
            { MessageBox.Show("Please Select CityName"); }

        }

        private void txtPassword_Leave(object sender, EventArgs e)
        {
            string SqlQuery = "Select CityName from userlogin where UserName='" + txtUserName.Text + "' and Password='" + txtPassword.Text + "'";
            DataTable dtddl = LeptonDataLayer.ExecuteDataTable(1, SqlQuery);
            if (dtddl.Rows.Count > 0)
            {
                for (int i = 0; i < dtddl.Rows.Count; i++)
                    ddlCityName.Items.Add(dtddl.Rows[i]["CityName"].ToString());
            }

            else
                MessageBox.Show("Incorrect UserName And Password");
        }



    }
}















当我运行以下代码时出现以下错误



对象引用未设置为对象的实例。



在我的mysql leptondata数据库中我有一个表userlogin,其中包含以下字段UserName,Password和CityName。





上面的代码有什么问题请告诉我








when i m running the following code i have following error

"Object reference not set to an instance of an object."

in my mysql leptondata database i have a table userlogin which have following field UserName,Password and CityName.


what is problem in above code pls tell me

推荐答案

错误发生在哪一行?了解该错误

对象引用未设置为对象实例的内容 [ ^ ]

为什么我会收到错误对象引用没有设置为对象的实例? [ ^ ]



练习完美调试

掌握调试工具g在Visual Studio 2010中 - 初学者指南 [ ^ ]

Visual Studio中的高级调试 [ ^ ]
In which line the error occurs? Understand about that error
What does Object reference not set to an instance of an object[^]
Why do I get the error "Object reference not set to an instance of an object"?[^]

Practice to debug perfectly
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Advanced Debugging in Visual Studio[^]


这篇关于当我运行以下代码时,我遇到了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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