I'm pretty new to ASP.NET and I think im not using it they way it's meant to be used with all the features packed into the latest .NET framework. I'm currently using .NET framework 4,0. There are some error in the code, don't mind them mind they way I seem to be using ancient techniques.
I have structured everything like this.
I file called webservice.cs, that file is packed with webmethods like this:
[WebMethod]
public string laggtillprodukt(string pro1, int pro2)
{
int sqlstatus;
string sqlinsertstringfull = "INSERT INTO t_produkter (produkt_namn) VALUES ('" + pro1 + "');" +
"SELECT produkt_id FROM t_produkter WHERE (produkt_id = SCOPE_IDENTITY()); " +
"INSERT INTO t_produktegenskaper (produkt_id, egenskaps_id) " +
"SELECT SCOPE_IDENTITY(), egen.egenskap_id " +
"FROM t_kopplingmallegenskaper as egen " +
"WHERE egen.mall_id = " + pro2 + ";";
sqlstatus = executeWriteSqlQuery(sqlinsertstringfull);
return "These values has been added to the db" + pro1 + " and " + pro2 + " SQL STATUS:" + sqlstatus;
}
In my code behind i do this to call the correct function(the one below has nothing to do with the webmethod before it was just to illustrate one of many SQL QUERIES.
protected void laggtillnymallbutton_Click(object sender, EventArgs e)
{
WebService globalwebservice = new WebService();
if (string.IsNullOrWhiteSpace(laggtillnymall.Text))
{
Label1.Text = "String cannot be empty or just whitespaces!";
}
else
{
globalwebservice.laggtillmall(laggtillnymall.Text.Trim());
Label1.Text = "Template added";
}
Can't I be doing this in a more effiecient way. I have constructed a general method that all webmethods either use to insertdata or to read data, saved me some code, but I've seen things like LINQ. That has far less code than I have. Please aid me or point me in a towards a not so ancient way of coding ;)