The previous code belonging to my teacher works 100%.
public int genaralctryresult;
public int countryidx;
public string photox;
public string ulkeismix;
public List<Country> item()
{
string sqlStatment = "select * from Country";
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr))
{
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlStatment, con))
{
cmd.Connection.Open();
System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
List<Country> emp = new List<Country>();
while (reader.Read())
{
Country country = new Country();
country.countryid = Convert.ToInt32(reader.GetValue(0));
country.countryname = reader.GetValue(2).ToString();
country.photo = reader.GetValue(1).ToString();
country.ctrypopulation = reader.GetValue(3).ToString();
country.ctrymultiply = Convert.ToInt32(reader.GetValue(4));
emp.Add(country);
}
//my area begin
if (ctryresult = 0) || (ctryresult = null) || (ctryresult = "")
{
generalactryresult = int(country.ctrypopulation) * int(countrymultiply)
insert into country ctryresult = generalactryresult
}
else if (ctryresult > 0)
{
generalactryresult = int(country.ctrypopulation) * int(countrymultiply)
update country ctryresult = genaralactryresult
}
reader.Close();
cmd.Connection.Close();
return emp;
}
}
}
public class Country
{
public int countryid { get; set; }
public string countryname { get; set; }
public string photo { get; set; }
public string ctrypopulation { get; set; }
public int ctrymultiply { get; set; }
public int ctryresult { get; set; }
}
public List<Country> Item { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Item = this.item();
}
else
{
foreach (string item in Request.Form.AllKeys)
{
if (item.Contains("btnSubmit"))
{
string id = item.Split('_')[1].Trim(); string sqlStatment = "SELECT * FROM country WHERE countryid=@Id";
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr))
{
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlStatment, con))
{
cmd.Parameters.AddWithValue("@Id", id);
cmd.Connection.Open();
System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
countryidx = Convert.ToInt32(reader.GetValue(0));
ulkeismix = reader.GetValue(1).ToString();
photox = reader.GetValue(2).ToString();
}
reader.Close();
cmd.Connection.Close();
}
}
break;
}
}
}
}
I made a mistake here, I couldn't figure out whether this should be in the web html part, but I thought it should be on the server side. In fact, I thought it was necessary to access the key of the table and update it, but this should be the correct one. here is the key id
<table>
<% foreach (var c in this.item())
{ %>
<tr>
<td>
<label><%=c.countryid%></label></td>
<td>
<input type="text" value='<%=c.countryname %>' /></td>
<td>
<input type="text" value='<%=c.photo%>' /></td>
<td>
<input type="radio" <%=c.countryname.ToLower() == "india" ? "checked" : "" %> /></td>
<td>
<input type="checkbox" <%=c.countryname.ToLower() != "india" ? "checked" : "" %> /></td>
<td>
<a href='Details.aspx?idno=<%=c.countryid %>'>Customer Detail</a> </td>
<td>
<button type="submit" name="btnSubmit_<%=c.countryid%>">View</button>
</td>
</tr>
<tr>
<td>
<input type="text" value='<%=c.ctrypopulation%>' /></td>
<td>
<input type="text" value='<%=c.ctrymultiply%>' /></td>
<td>
<input type="text" value='<%=c.ctryresult%>' /></td>
<td colspan="4">
<input type="text" value='<%=(c.ctrymultiply * c.ctryresult).ToString("N2")+"%"%>' /></td>
</tr>
<% } %>
</table>
Depending on whether the program works, there is both an insert and an update, but if it works, it will be wonderful.
Our teacher's previous code works percent by percent. Now, when the cyclic list starts, the result of each row should be written to the database, if any, the database variable should be updated, and if so, I would like to thank our teacher and offer my best regards.