---
title: "Visual Basic fetching data from mysql table"  
description: "Visual Basic fetching data from mysql table"  
author: "Anonymous User"  
published: 2013-06-11  
updated: 2013-06-12  
canonical: https://www.mindstick.com/forum/1042/visual-basic-fetching-data-from-mysql-table  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 2 minutes  

---

# Visual Basic fetching data from mysql table

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs), \
During Fetching [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) from the [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) i get following line of [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing)\
**"Invalid object name 'h'"** My line of [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) as following\
**Dim h As [Decimal](https://www.mindstick.com/forum/34709/please-write-a-program-for-decimal-to-binary-conversion-in-c-sharp)**\
'some code\
**cmd2 = New [SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder)("[insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) into h [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) KvotaX from dbo.Utakmice where ID=@s1 ", conn)** **cmd2.Parameters.AddWithValue("@s1", myReader.GetInt32(1))**\
'some code\
**f = cmd2.ExecuteNonQuery()**\
I don't know what I'm [doing wrong](https://answers.mindstick.com/qa/36736/what-are-indians-doing-wrong-on-whatsapp). KvotaX from dbo.Utakmice data type is real.\
Thanks in advance. \

## Replies

### Reply by AVADHESH PATEL

Hi Alex,\
You can not set the value of **h** using a SQL statement, hence you can try as following \

```
Dim h As Decimalcmd2 = New SqlCommand("select KvotaX from dbo.Utakmice where ID=@s1 ", conn)cmd2.Parameters.AddWithValue("@s1", myReader.GetInt32(1))h = Convert.ToDecimal(cmd2.ExecuteScalar)
```

**\**You select the record corresponding to the parameter passed in and then read the return value of the ExecuteScalar method. Note that this works only if the query returns one record and only one column. Better to be safe checking the return value before assigning to the decimal\

```
Dim o = cmd2.ExecuteScalarif o IsNot Nothing Then    h = Convert.ToDecimal(o)    .....End If
```

**\**However, your code hints to the fact that you are trying to get the value for the s1 parameters reading from an open MySqlDataReader. This could not be possible because, usually, the connection used by the datareader is busy till the datareader remains open.\


---

Original Source: https://www.mindstick.com/forum/1042/visual-basic-fetching-data-from-mysql-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
