Click here to Skip to main content
15,881,882 members

I need some help, I"m trying to retrieve data into textbox

Tobynate asked:

Open original thread
i"m to retrieve data from a mysql database to a read only textbox, i"m using a stored procedure  with input parameter i"m also using dapper as my mapper, and  class library as model for my data, any ideas pleas<pre lang="text">
e?

What I have tried:

Below is from my books library class
C#
lass library
public list<BooksModel>MyQuantity{get; set;}
Public string QuantiyNew{get {return MyQuantity.ToString();set{;}}}


Below is from my sqlconnector class, I'm using two data storage, Mysql and textile so I created an enum I'm also using an interface IDataconnection
C#
public class Sqlconnector: iDataconnection
public List<BooksModel> GetStockQuantity(BooksModel modell)
        {
          List<Booksmodel> output;
            using (IDbConnection connection = new MySqlConnection(GlobalConfig.CnnString(mydb)))
            {
                output = (BooksModel)connection.Query<BooksModel>("Book_GetAll_By_BookTitle", new { book_titlesp = bookname }, commandType: CommandType.StoredProcedure);
               
modell.MyQuantity= output;
            }
            //var invoice = connection.Get<Invoice>(1);
            return output;
        }

Now this is the code behind my UI design
C#
Public partial class books item: Form
{
List<BooksModel> stocktotal =new List<BooksModel>();
Private void Stock now()
{
BooksModel model= new BooksModel(txtbt1.text,null,null,null,null,null);
stocktotal= GlobalConfig.Connection.GetStockQuantity(model);

}
Private void WireUpStockTotal()
{
stocktotaltxt.Data bindings.Clear();
stock total.Add(new BooksModel(){QuantityAgain= "C#"});
stocktotaltxt.DataBindings.Add("Text", stock total[0],"QuantityAgain");
}
Private void txtbt1_Leave(object sender, EventArgs e)
{
WireUpStockTotal();
Stock now();
}

the storage procedure is simply a "SELECT * FROM booktable WHERE book name= booksp;"



I'm trying to get the result of my query into the stocktotaltxt textbox, but whenever I run this code it goes to my sqlconnector class and throws an exception of 'object reference not set to an instance of an object
BooksLibrary.Model.Transaction.MyQuantity.get returned null' at the public string QuantityAgain{get {return MyQuantity.ToString();} set{;}}
Tags: C#, Dapper, Stored procedure

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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