Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
sorry im bad at coding but i need this,

well..
in my table called Products
got 2 column there is Product and Price
in Price column contains a decimal value 1000

can i get that value(1000) to be a variable so i can use it into arithmetic function?
and it seems to connect the database to my form is incorrect as well,

pls modify all my source! and what i need to add! thanks
I would appreciate any help!

What I have tried:

This's the DataAccessLayer
DataAccess.cs

namespace CS_Sistem_Managemen_Restoran
{
    class DataAccess
    {
        public SqlConnection con;

        public void Connection(string spName = null)
        {
            string strConnect = "Server=PC\\SQLEXPRESS;Database=MyLoginApp;Trusted_Connection=True;";
            SqlConnection conn = new SqlConnection();
            SqlConnection dt = new SqlConnection();
            

            try
            {
                //Connect to the database
                conn = new SqlConnection(strConnect);
                conn.Open();



                //Execute command
                SqlCommand cmd = new SqlCommand(spName, conn);
                SqlCommand command = conn.CreateCommand();
                SqlDataReader dr = cmd.ExecuteReader();

                


            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
         
    }
}


Form1.cs BtnHitung
 private void btnHitung_Click(object sender, EventArgs e)
        {
            DataAccess conss = new DataAccess();
            conss.Connection();
            DataTable dt = new DataTable("Products");

            //declare
            Double BasoSUCost = Convert.ToInt32(dt.Rows[1]["price"].ToString());
	    Double ItemBasoSU;
	    Double TotalBasoSU;


if (int.TryParse(txtBasoSU.Text, out NumberofOrder))
            {
                ItemBasoSU = Double.Parse(txtBasoSU.Text);
                TotalBasoSU = BasoSUCost * ItemBasoSU;
		
		txtTotal.Text = String.Format("Rp. {0:N} ", TotalBasoSU);
	    }
	}
Posted
Updated 4-Sep-18 4:45am

1 solution

If you weren't going to listen when I told you yesterday: C# VS, sqlexpress - how do I use the datatable value and make a simple times calculation with textbox and appear the result in second textbox C#?[^] then why are you askign the same question again today?

I assumed after the extensive conversation we had that you had actually learned something... :sigh:
 
Share this answer
 
Comments
Muhammad nur Ihsan 4-Sep-18 10:49am    
cmon man Dx im still confuse with it give an example again please to connect my datatable to my Form1
OriginalGriff 4-Sep-18 10:50am    
Do you want to try typing that again, in English this time?
Muhammad nur Ihsan 4-Sep-18 10:52am    
its rly hard to study a c# by self for me because in my universty doesn't give any clue about it :(
Muhammad nur Ihsan 4-Sep-18 11:32am    
please can you explain one more time?
OriginalGriff 4-Sep-18 12:31pm    
Which bit - we covered a whole load of ground yesterday, and you have ignored all of it ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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