How to connect MySQL database? this code base,there were no erors. But can not insert data
NickName:Dinuwan Kalubowila Ask DateTime:2019-06-21T14:24:58

How to connect MySQL database? this code base,there were no erors. But can not insert data

using MySql.Data.MySqlClient;
using System.Data;

public String connectionString = @"server=localhost;port=3306;user id=root;database=Product;persistsecurityinfo=True;password=xxxxxx@;";


protected void btnInsert_Click(object sender, EventArgs e)
{
    MySqlConnection mySqlCon = new MySqlConnection(connectionString);

    try
    {
        using (mySqlCon)
        {
            mySqlCon.Open();

            MySqlCommand mySqlCmd = new MySqlCommand("Proc_Store_Products", mySqlCon);
            mySqlCmd.CommandType = CommandType.StoredProcedure;
            mySqlCmd.Parameters.AddWithValue("_productId", Convert.ToInt32(hfProductID.Value == "" ? "0" : hfProductID.Value));
            mySqlCmd.Parameters.AddWithValue("_productCode", txtproductCode.Text.Trim());
            mySqlCmd.Parameters.AddWithValue("_productName", txtproductName.Text.Trim());
            mySqlCmd.Parameters.AddWithValue("_price", Convert.ToDecimal(txtprice.Text.Trim()));
            mySqlCmd.Parameters.AddWithValue("_description", txtdescription.Text.Trim());

            mySqlCmd.ExecuteNonQuery();

            clear();
            lblSuccessMsg.Text = "Submitted Successfully";
        }


    }
    catch (Exception ex)
    {
        lblErrorMsg.Text = ex.Message;
    }

This is the SP code

DELIMITER $$ 
CREATE DEFINER=root@localhost PROCEDURE Proc_Store_Products(
    _productId int, 
    _productCode varchar(20), 
    _productName varchar(40), 
    _price decimal(18,2), 
    _stock int, 
    _description varchar(200)
) BEGIN
IF _productId = 0 then
    INSERT INTO productInfo(productCode,productName,price,stock,description) 
    VALUES(_productCode,_productName,_price,_stock,_description);

else
    UPDATE productInfo
    SET
    productCode = _productCode,
    productName = _productName,
    price = _price,
    stock = _stock,
    description = _description
    WHERE
    productId = _productId;

END IF;
END$$ DELIMITER ;

Copyright Notice:Content Author:「Dinuwan Kalubowila」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56697936/how-to-connect-mysql-database-this-code-base-there-were-no-erors-but-can-not-i

More about “How to connect MySQL database? this code base,there were no erors. But can not insert data” related questions

How to connect MySQL database? this code base,there were no erors. But can not insert data

using MySql.Data.MySqlClient; using System.Data; public String connectionString = @"server=localhost;port=3306;user id=root;database=Product;persistsecurityinfo=True;password=xxxxxx@;"; protected...

Show Detail

Read/insert Chinese data from mysql database saved by php code

I want to use ruby to read/insert data to a mysql database, onto which data were saved by a php code. When I read Chinese data, it does not appear correctly. It appears like 刘佳. But in a php pa...

Show Detail

Connect Android With MySql Restful Data Base?

I want to connect a mobile application (Android) with MySQL restful web service to do the following 1- save the data of the client user (Android Mobile Application) to MySQL Restful data base whi...

Show Detail

how to connect and insert and retrieve data from database?

$con = mysql_connect("localhost","music123_sri","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("music123_telugu", $con); $sql="INSERT INT

Show Detail

Insert data to mysql database

I want to insert data from android to mysql database This is php code $connect = mysqli_connect("localhost","root","123423","jacccccttt"); if(mysqli_connect_errno($connect)) {

Show Detail

About Insert data to mysql database

CODE: import mysql.connector from bs4 import BeautifulSoup import requests URL = "https://parade.com/937586/parade/life-quotes/" web_page = requests.get(URL) soup = BeautifulSoup(web_page.

Show Detail

Connect an ios app with mysql database

I've a doubt if it is possible connect an ios app using swift directly with a mysql database without a need of a RestAPI. For example: i have a website with a mysql database and want to make an ap...

Show Detail

How to write(Insert) pandas DatafFrame directly to MySQL database?

I am extracting data from google sheet and I have to insert that data frame to MySQL localhost database. I have tried this, and it doesn't work for me: How to insert pandas dataframe via mysqldb ...

Show Detail

How do i connect mysql database and insert data into it using android code

I have mysql database on my hosting server On simple android application I have feedback form and on submit I want to insert data into mysql database which is on server . I tried google and foun...

Show Detail

Insert Arabic text into MySQL data-base -PHP

In my Android app. I need to update on data-base directly, so I need php code to receive a JSON object. However, I attempt to insert Arabic values into MySql database field; but for an unknown reas...

Show Detail