473,383 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

how to avoid error CommandText property has not been initialized properly

3
database is in the sqlYog, while i run this program i am getting the error CommandText property has not been initialized properly..? please help me

Expand|Select|Wrap|Line Numbers
  1. Imports MySql.Data.MySqlClient Imports System.Data
  2.  
  3. Partial Class login Inherits System.Web.UI.Page
  4.  
  5. Public dbconn As New MySqlConnection
  6. Public sql As String
  7. Public dbcomm As New MySqlCommand
  8. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  9.  
  10.     dbconn = New MySqlConnection("data source= localhost; user id=root; password=search; database=bookstore;")
  11.     dbconn.Open()
  12.     dbcomm.Connection = dbconn
  13.  
  14. End Sub
  15.  
  16. Protected Sub btn_login_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_login.Click
  17.  
  18.     Try
  19.         dbcomm = New MySqlCommand(sql, dbconn)
  20.  
  21.         sql = "select * from bookstore.lib_user where username=@username  and password=@password"
  22.  
  23.         dbcomm.Parameters.AddWithValue("@username", txt_username.Text)
  24.         dbcomm.Parameters.AddWithValue("@password", txt_password.Text)
  25.  
  26.         Dim dbadpt As New MySqlDataAdapter(dbcomm)
  27.         Dim dt As New DataTable()
  28.         dbadpt.Fill(dt)
  29.         If dt.Rows.Count > 0 Then
  30.             MsgBox("login is suceesfull")
  31.         Else
  32.             Literal1.Text = "invalid login"
  33.         End If
  34.  
  35.     Catch ex As Exception
  36.         MsgBox("read this error: " + ex.Message)
  37.     End Try
  38. End Sub
  39. End Class
Dec 27 '13 #1
1 3769
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

On lines 19 and 21, you create your command with a blank variable, then you populate the variable. That's backwards.
Dec 27 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Marc W | last post by:
Hello, I am trying to write some code, I get a compiler error, but the help about it is very limited. (I am working with MSVC++ 6.0.) Could you give me a hint what is wrong here please? ...
0
by: Raphael Rodrigues | last post by:
Hi... I uninstalled my VS 2005 Express and when i try to reinstall them in my computer the TOOLBOX's content dissapear!!! I've tried "Choose Items" with right button in TOOLBOX panel but "Error...
0
by: juli jul | last post by:
Hello, I have such an error: An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll Additional information: Internal error: GDI+ is...
0
by: iyuen | last post by:
Have anyone seen this error? I'm trying to use a managed C++ class in an VB6 application. For each class definition in my header files (.h) I put in front of the defintion. Then I use regasm to...
3
by: Java script Dude | last post by:
Has anybody hacked a stack parser for Mozilla Error stack property. Some basic regular expressions would work well, but my time is a little tight of late. Basically I would like to parse out,...
0
by: neoupadhyay | last post by:
ExecuteScalar: CommandText property has not been initialized public static bool GridView4_RowUpdate(string ItemDescription, decimal AnnualCost, Single CPIChildCost, decimal ChildCostItemTotal,...
0
by: selvamariappan | last post by:
Hi all, I have already used InitGraph Eg: initgraph(&gdr,&gmd,""); In Initgraph I have checked the Graphics option in Linker Options. Still Iam getting this error. I want a solution. Can somebody...
7
by: Qtip23 | last post by:
Hi All, I have been creating a database that basically searches for data based on the SQL string created. So far, I was successful until I received -- Error Number 3270 - Property Not Found --...
5
by: tetsuo2030 | last post by:
Greetings. I have VBA code running from a combobox's AfterUpdate event which sets a querydef to a particular SQL statement based on the selection. Reason: rather than saving a bunch of queries, I...
1
by: katikatii | last post by:
this is a query which works in mysql but does not work in the jsp SELECT (@rownum:=@rownum+1) AS pos, fname,lastname,othername,clas,(( tblbot.mtc+tblmot.mtc+tbleot.mtc)/3+ ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.