hi guys i have problem with my code
here is my code

Public Sub increment()
        Dim dr As SqlDataReader

        If con.State = ConnectionState.Closed Then
            con.ConnectionString = (strconnection)
            con.Open()

        End If

        Dim str As String = "Select CUSTOMERID from tbl_Customer"

        cmd = New SqlCommand(str, objconnection)
        dr = cmd.ExecuteReader


        While (dr.Read())

            TXTCUSTOMERD.Text = (dr.Item("CUSTOMERID"))

        End While

        If TXTCUSTOMERD.Text = "" Then
            TXTCUSTOMERD.Text = 0
            TXTCUSTOMERD.Text = Val(TXTCUSTOMERD.Text) + 1

        Else
            TXTCUSTOMERD.Text = Val(TXTCUSTOMERD.Text) + 1

        End If


        dr.Close()

    End Sub

pls. i need your help regarding this..
God bless!

Try to change it to:

con.ConnectionString = strconnection
If con.State = ConnectionState.Closed Then
	con.Open()
End If

Dim str As String = "Select CUSTOMERID from tbl_Customer"

cmd = New SqlCommand(str, objconnection)
Dim dr As SqlDataReader = cmd.Executereader()

While (dr.Read())
		'If the id column is not integer, chnage "int" with correct type (stirng I would say)!
	TXTCUSTOMERD.Text = CInt(dr("CUSTOMERID"))
End While

If String.IsNullOrEmpty(TXTCUSTOMERD.Text) Then
	TXTCUSTOMERD.Text = 0
	TXTCUSTOMERD.Text = Conversion.Val(TXTCUSTOMERD.Text) + 1
Else
	TXTCUSTOMERD.Text = Conversion.Val(TXTCUSTOMERD.Text) + 1
End If
dr.Close()

hi i tried ur code but it keeps getting the same error message >.<

this line :

Dim dr As SqlDataReader = cmd.ExecuteReader()

What error?
YOu have to tell me it.

executereader: connection property has not been initialized..

i solved this problem already

hi,
i am mudassar,i am a student i have to submit my project on monday ,project of property adviser software,but i could not remove this error,plz got me out of here thanks

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 System.Data.SqlClient;

namespace B_14941
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Form3 qa = new Form3();
            qa.Show();

        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            string connectionString = "Data Source=localhost;Database=electtronic;Integrated Security=False;User ID=sa;Password=xxx;Connect Timeout=15;Encrypt=False;";
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("SELECT uname,pass FROM users WHERE uname='" + textBox1.Text + "' and pass='" + textBox2.Text + "'", con);
            //-----------------------------------------------------
           // SqlConnection lgnConnection = new SqlConnection();
            //lgnConnection.connectionString = "Data Source=localhost;Database=electtronic;Integrated Security=False;User ID=sa;Password=xxx;Connect Timeout=15;Encrypt=False;";
            con.Open();
           // SqlCommand cmd = new SqlCommand("SELECT uname,pass FROM users WHERE uname='" + textBox1.Text + "' and pass='" + maskedTextBox1.Text + "'", lgnConnection);
            SqlDataReader dr;
            dr = cmd.ExecuteReader();          :-O (HERE I GOT ERROR):-O
            while (dr.Read())
            {
                if (dr["uname"].ToString() == textBox1.Text && dr["pass"].ToString() == textBox2.Text)
                {
                    Close();

                }
                else
                {
                    Close();

                }
            }
            dr.Close();
            con.Close();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.