Home problems with calling helperfunction
Reply: 0

problems with calling helperfunction

pfandflaschen
1#
pfandflaschen Published in 2017-12-07 20:38:58Z

hi in one of my cshtml's i call my helperfunction. but my programm wont go into it.

code-part (where i call the function):

if (var1== 0)
{
  <div class="row"><p> available products </p> </div> 
}
else
{
helperno1.helperfct(var1); 
}

helper-code.

@using System.Configuration;
@using MySql.Data.MySqlClient;


@helper helperfct(int x)
{
 const string constring = 
 "server=127.0.0.1;database=db1;uid=user;pwd=123456"; 
 MySqlConnection con = new MySqlConnection(constring);
try
{
con.Open(); 

MySqlCommand cmd;

cmd = con.CreateCommand();
cmd.CommandText = "SELECT name FROM products WHERE ID =" + x;

MySqlDataReader r = cmd.ExecuteReader();

while (r.Read())
{
   <h2> available products (@r["name"])</h2>
}


}
catch (Exception e)
{
<li>
    <p class="error">error.error.error</p>
    <pre>@e.Message</pre>
</li>
}
}

the program jumps to the helperpage with the helperfunction to the function but won't go in it (directly jumps to the end).

any idea what might be the cause for this?

thanks in advance for answering.

total newbie to this so please lots of explaining

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.314288 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO