Click here to Skip to main content
16,016,087 members

Comments by Muhammad nur Ihsan (Top 22 by date)

Muhammad nur Ihsan 16-Sep-18 4:15am View    
can you explain that for?
what do i put inside here?
using (StreamReader sr = new StreamReader(openpath))
    {
        // read the text
    }
Muhammad nur Ihsan 5-Sep-18 0:40am View    
Deleted
ok now this's my DAL.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)
            {
                
            }
        }
         
    }
}


this's my form1 Button
private void btnHitung_Click(object sender, EventArgs e)
        {
            DataAccess conn = new DataAccess();
            conn.Connection();
            DataTable dt = new DataTable("Products");

            //declare
            Double BasoSUCost = Convert.ToInt32(dt.Rows[1]["price"].ToString());
            Double ItemBasoSU; Double HargaBasoSU;
            
 if (int.TryParse(txtBasoSU.Text, out NumberofOrder))
            {
                ItemBasoSU = Double.Parse(txtBasoSU.Text);
                HargaBasoSU = BasoSUCost * ItemBasoSU;

 txtTotal.Text = String.Format("Rp. {0:N} ", HargaBasoSU);    
}


gets me error after run in
Double BasoSUCost = Convert.ToInt32(dt.Rows[1]["price"].ToString());


IndexOutOfRangeException 'There is no row at Position 1.'

why is that
Muhammad nur Ihsan 4-Sep-18 11:32am View    
please can you explain one more time?
Muhammad nur Ihsan 4-Sep-18 10:52am View    
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 10:49am View    
cmon man Dx im still confuse with it give an example again please to connect my datatable to my Form1