Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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();
        }

C#
private void button1_Click(object sender, EventArgs e)
       {

C#
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;

C#
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");
        }



    }
}







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
Posted
Comments
Richard Deeming 3-Sep-14 8:36am    
Your code is susceptible to SQL Injection[^].

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900