Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7583901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:47:41+00:00 2026-05-30T18:47:41+00:00

Imports System.Data.SqlClient Public Class Form3 Private cs As New SqlConnection(Data Source=HUSAIN-PC;Initial Catalog=final1;Integrated Security=True) Private

  • 0

Imports System.Data.SqlClient

Public Class Form3

Private cs As New SqlConnection("Data Source=HUSAIN-PC;Initial 

Catalog=final1;Integrated Security=True”)

Private da As New SqlDataAdapter
Private ds As New DataSet
Public dr As SqlDataReader
Public cmd As New SqlCommand
Private sql As String
Private sqlsel As String
Dim Bal As String
Dim id As String
Dim amt As String

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    cs.Open()
    cmd.Connection = cs
    amt = TextBox2.Text
    id = TextBox1.Text
    sqlsel = "SELECT (Bal) FROM db5 WHERE Id='" + id + "'"
    da.InsertCommand = New SqlCommand(sqlsel, cs)
    dr = cmd.ExecuteReader
    If dr.HasRows = True Then
        While (dr.Read())
            Bal = dr("Id")
        End While
    End If
    dr.Close()
    MessageBox.Show("Balance is :" + Bal)

    Dim total As String = Bal + amt

    sql = "UPDATE db5 SET Bal='" + total + "' WHERE Id='" + id + "'"
    da.InsertCommand = New SqlCommand(sql, cs)
    da.InsertCommand.ExecuteNonQuery()
    MessageBox.Show("updated")
End Sub

End Class

This is my VB code to retrieve a value from the SQL DB…the Update statement is running fine bt wen i write the select i get an exception in the code:
dr=cmd.ExecuteReader
“ExecuteReader: CommandText property has not been initialized”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:47:42+00:00Added an answer on May 30, 2026 at 6:47 pm

    Look at this code:

    sqlsel = "SELECT (Bal) FROM db5 WHERE Id='" + id + "'"
    da.InsertCommand = New SqlCommand(sqlsel, cs)
    dr = cmd.ExecuteReader
    

    You’re specifying an InsertCommand as a SELECT query, but then you’re calling ExecuteReader on a completely separate SqlDataReader… which hasn’t got a query configured, as per the error message.

    That’s why you’re getting this specific error, but there are lots of problems with this code:

    • You should be creating a new SqlConnection / SqlCommand etc every time you want to execute a query
    • You should be using Using statements to automatically close them
    • You shouldn’t have instance variables for these – they should be local variables
    • I see no reason to use a DataAdapter here in the first place – just use SqlCommand.ExecuteNonQuery
    • Very important: You should be using parameterized SQL instead of including values directly in your SQL. See the Bobby Tables site for more information about this topic.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imports System.Data.OleDb Public Class Log Private mConnectionString As String = Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=1521)))(CONNECT_DATA=(SID=xxx)(SERVER=DEDICATED)));User Id=xxx;Password=xxx; Dim
I have this class that contains vars for db connection; Imports Microsoft.VisualBasic Imports System.Data.SqlClient
I have the following code: Imports System.Data Partial Class Students_AddWishes Inherits System.Web.UI.Page Public dt
my global.asax looks like this Imports Castle.Windsor Imports Castle.Windsor.Configuration.Interpreters Public Class MvcApplication Inherits System.Web.HttpApplication
I am trying to import the following: Imports System Imports System.Data Imports System.Data.SqlClient In
Hers the form code: Imports TechSupportData Public Class frmOpenIncidents Private Sub frmOpenIncidents_Load(ByVal sender As
We are developing a c# application that imports address-data into a CRM-system. The CSV-file
Should I use this. Imports System.IO Dim myStream As New Stream or this.. Dim
Im trying push some data into a CRM system via an XML import. I
The problem is during inserting data from staging table during import routine. The system

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.