Skip to content
Loading
  • Rafnas T P
    +1
    hi,
    first modify below function
    1. string con;  
    2. public void PullData()    
    3.        {    
    4.     
    5.            if (godinalabel.Text == "2017")    
    6.            {    
    7.               con = cs2017;    
    8.            }    
    9.            else if (godinalabel.Text == "2018")    
    10.            {    
    11.                con cs2018;    
    12.            }    
    13.     
    14.        }   
     then modify below line
    1. using (SqlConnection openCon = new SqlConnection(con))
    +1
  • Rafnas T P
    +1
    where did you calling PullData() method,
    you have to call this on page load or before using connection 
    +1
  • 0
    Error is
     
    The ConnectionString property has not been initialized
     
    Line 15
    1. private void Izvjestajoprodanimartiklima()  
    2.         {
    3.             using (SqlConnection openCon = new SqlConnection(con))  
    4.             {  
    5.                 String saveStaff = "SELECT  * from partners  ";  
    6.                 Console.WriteLine(saveStaff);
    7.                 openCon.Open();  
    8.                 using (SqlDataAdapter querySaveStaff = new SqlDataAdapter(saveStaff, con))
    9.                 {  
    10.                     DataTable dt = new DataTable();  
    11.                     DataColumn column = new DataColumn();  
    12.                     column.DataType = System.Type.GetType("System.Int32");  
    13.                     column.ColumnName = "Redni broj";  
    14.                     column.AutoIncrement = true;  
    15.                     column.AutoIncrementSeed = 1;  
    16.                     column.AutoIncrementStep = 1;  
    17.                     dt.Columns.Add(column);  
    18.                     int index = -1;  
    19.                     foreach (DataRow row in dt.Rows)  
    20.                     {  
    21.                         row.SetField(column, ++index);  
    22.                     }
    23.                     querySaveStaff.Fill(dt);  
    24.                     dataGridView1.DataSource = dt;  
    25.                     dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;  
    26.                     dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
    27.                     dataGridView1.Update();  
    28.                     dataGridView1.Refresh();  
    29.                 }
    30.             } 
    31.         } 
     
    0
  • 0
    Thank you
    0