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
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
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;
}
return output;
}
Now this is the code behind my UI design
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{;}}