Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Ad icon
ZTE MF283U 4G Unlocked Router (Used)
ayanthamaxi
Updated:
Sunday at 8:26 PM
ලංකාවේ හොඳම උපකාරක පන්ති සහ ගුරුවරුන් එකම තැනකින් - TopTuition.lk
dulithapathum
Updated:
Saturday at 8:07 AM
Colombo
RidhMathraa ’26 🎶✨
Tmadhusanka
Updated:
Wednesday at 11:58 PM
Ad icon
Colombo
PXN V10 Pro Direct Drive Racing Wheel (Under Warranty)
Abdur Rahman
Updated:
Wednesday at 10:23 PM
Ad icon
USDT ණය සේවාව - USDT Loan Service
පුරවැසියා
Updated:
Wednesday at 4:54 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
C# For Loop Problem!
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="isurutmv" data-source="post: 24192046" data-attributes="member: 470006"><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">[PHP]</span></p><p><span style="font-size: 12px"> private DataSet getEntity(Entity entity, String SELECT_TEXT, String[][] tableDetailsArray, String tableName) {</span></p><p><span style="font-size: 12px"> List<Entity> list = new List<Entity>();</span></p><p><span style="font-size: 12px"> try {</span></p><p><span style="font-size: 12px"> MySqlCommand cmd = new MySqlCommand();</span></p><p><span style="font-size: 12px"> connection.Open();</span></p><p><span style="font-size: 12px"> cmd.Connection = connection;</span></p><p><span style="font-size: 12px"> SELECT_TEXT = "SELECT " + (entity.RowsCount > 0 ? "COUNT(*)" : "*") + " FROM `" + tableName + "` WHERE";</span></p><p><span style="font-size: 12px"> //SELECT_TEXT = (entity.RowsCount > 0 ? "SELECT COUNT(*) FROM (" : "") + "SELECT * FROM `" + tableName + "` WHERE";</span></p><p><span style="font-size: 12px"> String param = "";</span></p><p><span style="font-size: 12px"> //String[][] arr = tableDetails.ToArray();</span></p><p><span style="font-size: 12px"> bool isIdRunId = false;</span></p><p><span style="font-size: 12px"> /*if(tableName == "buying_invoice") {</span></p><p><span style="font-size: 12px"> //MessageBox.Show(getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[4][0])).ToString());</span></p><p><span style="font-size: 12px"> String s = (getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[4][0])).ToString() != "1/1/0001 12:00:00 AM").ToString();</span></p><p><span style="font-size: 12px"> }*/</span></p><p><span style="font-size: 12px"> for (int i = 0; i < tableDetailsArray.Length; i++) {</span></p><p><span style="font-size: 12px"> bool canBeDouble = false;</span></p><p><span style="font-size: 12px"> try {</span></p><p><span style="font-size: 12px"> if (tableDetailsArray[i][1].Length > 5) {</span></p><p><span style="font-size: 12px"> canBeDouble = true;</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> } catch (Exception) {</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> if (tableDetailsArray[i][1].Substring(0, 3) == "int" && tableDetailsArray[i][5] == "auto_increment" && Convert.ToInt32(getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))) > 0) {</span></p><p><span style="font-size: 12px"> param += " AND `" + tableDetailsArray[i][0] + "` LIKE @" + tableDetailsArray[i][0];</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])));</span></p><p><span style="font-size: 12px"> isIdRunId = true;</span></p><p><span style="font-size: 12px"> } else if (tableDetailsArray[i][1].Substring(0, 3) == "int" && tableDetailsArray[i][5] != "auto_increment" && Convert.ToInt32(getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))) > -1) {</span></p><p><span style="font-size: 12px"> param += " AND `" + tableDetailsArray[i][0] + "` LIKE @" + tableDetailsArray[i][0];</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])));</span></p><p><span style="font-size: 12px"> } else if ((tableDetailsArray[i][1] == "date" || tableDetailsArray[i][1].Substring(0, 4) == "date") && getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])).ToString() != "1/1/0001 12:00:00 AM") {</span></p><p><span style="font-size: 12px"> if (entity.dateCondition == null) {</span></p><p><span style="font-size: 12px"> param += " AND DATE(`" + tableDetailsArray[i][0] + "`) LIKE @" + tableDetailsArray[i][0];</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropDateValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])));</span></p><p><span style="font-size: 12px"> } else {</span></p><p><span style="font-size: 12px"> try {</span></p><p><span style="font-size: 12px"> if (entity.dateCondition[tableDetailsArray[i][0]] != null) {</span></p><p><span style="font-size: 12px"> param += " AND (DATE(`" + tableDetailsArray[i][0] + "`) " + entity.dateCondition[tableDetailsArray[i][0]][0] + " @" + tableDetailsArray[i][0] + "1" + " AND @" + tableDetailsArray[i][0] + "2" + ")";</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0] + "1", entity.dateCondition[tableDetailsArray[i][0]][1]);</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0] + "2", entity.dateCondition[tableDetailsArray[i][0]][2]);</span></p><p><span style="font-size: 12px"> } else {</span></p><p><span style="font-size: 12px"> param += " AND DATE(`" + tableDetailsArray[i][0] + "`) LIKE @" + tableDetailsArray[i][0];</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropDateValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])));</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> } catch (Exception) {</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> } else if (canBeDouble && tableDetailsArray[i][1].Substring(0, 6) == "double" && Convert.ToDouble(getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))) > 0) {</span></p><p><span style="font-size: 12px"> if (entity.doubleCondition == null) {</span></p><p><span style="font-size: 12px"> param += " AND `" + tableDetailsArray[i][0] + "` = @" + tableDetailsArray[i][0];</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])));</span></p><p><span style="font-size: 12px"> } else {</span></p><p><span style="font-size: 12px"> try {</span></p><p><span style="font-size: 12px"> if (entity.doubleCondition[tableDetailsArray[i][0]] != null) {</span></p><p><span style="font-size: 12px"> param += " AND `" + tableDetailsArray[i][0] + "` " + entity.doubleCondition[tableDetailsArray[i][0]] + " @" + tableDetailsArray[i][0];</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])));</span></p><p><span style="font-size: 12px"> } else {</span></p><p><span style="font-size: 12px"> param += " AND `" + tableDetailsArray[i][0] + "` = @" + tableDetailsArray[i][0];</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])));</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> } catch (Exception) {</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> } else if (tableDetailsArray[i][5] != "auto_increment" && getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])) != null && getPropType(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])) != "System.Double" && getPropType(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])) != "System.Int32" && (getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])).ToString() != "1/1/0001 12:00:00 AM")) {</span></p><p><span style="font-size: 12px"> param += " AND `" + tableDetailsArray[i][0] + "` LIKE @" + tableDetailsArray[i][0];</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])));</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> if (entity.ManualQueries != null) {</span></p><p><span style="font-size: 12px"> param += " " + entity.ManualQueries;</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> if (!isIdRunId) {</span></p><p><span style="font-size: 12px"> param = " AND `id` != '0'" + param;</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> param = param.Substring(4);</span></p><p><span style="font-size: 12px"> if (entity.OrderBy != null) {</span></p><p><span style="font-size: 12px"> param += " ORDER BY " + entity.OrderBy;</span></p><p><span style="font-size: 12px"> /*param += " ORDER BY @orderBy @orderType";</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@orderBy", entity.OrderBy);</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@orderType", entity.OrderType);*/</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> if (entity.RowsCount < 1 && entity.LimitStart > -1) {</span></p><p><span style="font-size: 12px"> param += " LIMIT @limitStart , @limitEnd";</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@limitStart", entity.LimitStart);</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@limitEnd", entity.LimitEnd);</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> /*if(entity.OrderBy != null) {</span></p><p><span style="font-size: 12px"> param += " ORDER BY @orderBy @orderType";</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@orderBy", entity.OrderBy);</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@orderType", entity.OrderType);</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> if(entity.LimitStart > -1) {</span></p><p><span style="font-size: 12px"> param += " LIMIT @limitStart , @limitEnd";</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@limitStart", entity.LimitStart);</span></p><p><span style="font-size: 12px"> cmd.Parameters.AddWithValue("@limitEnd", entity.LimitEnd);</span></p><p><span style="font-size: 12px"> }*/</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px"> SELECT_TEXT += param + ";";</span></p><p><span style="font-size: 12px"> //SELECT_TEXT += param + (entity.RowsCount > 0 ? ") AS cou" : "") + ";";</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px"> cmd.CommandText = SELECT_TEXT;</span></p><p><span style="font-size: 12px"> cmd.Prepare();</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px"> DataSet dataSet = new DataSet();</span></p><p><span style="font-size: 12px"> new MySqlDataAdapter(cmd).Fill(dataSet);</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px"> connection.Close();</span></p><p><span style="font-size: 12px"> return dataSet;</span></p><p><span style="font-size: 12px"> } catch (Exception) {</span></p><p><span style="font-size: 12px"> connection.Close();</span></p><p><span style="font-size: 12px"> return null;</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">[/PHP]</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">mcn me code eke for loop eka iwara nowenna hethuwa poddak kiyapanko <img src="/styles/default/xenforo/smilies/default/dull.gif" class="smilie" loading="lazy" alt=":dull:" title="Dull :dull:" data-shortname=":dull:" /></span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px"></span></p></blockquote><p></p>
[QUOTE="isurutmv, post: 24192046, member: 470006"] [SIZE="3"] [PHP] private DataSet getEntity(Entity entity, String SELECT_TEXT, String[][] tableDetailsArray, String tableName) { List<Entity> list = new List<Entity>(); try { MySqlCommand cmd = new MySqlCommand(); connection.Open(); cmd.Connection = connection; SELECT_TEXT = "SELECT " + (entity.RowsCount > 0 ? "COUNT(*)" : "*") + " FROM `" + tableName + "` WHERE"; //SELECT_TEXT = (entity.RowsCount > 0 ? "SELECT COUNT(*) FROM (" : "") + "SELECT * FROM `" + tableName + "` WHERE"; String param = ""; //String[][] arr = tableDetails.ToArray(); bool isIdRunId = false; /*if(tableName == "buying_invoice") { //MessageBox.Show(getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[4][0])).ToString()); String s = (getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[4][0])).ToString() != "1/1/0001 12:00:00 AM").ToString(); }*/ for (int i = 0; i < tableDetailsArray.Length; i++) { bool canBeDouble = false; try { if (tableDetailsArray[i][1].Length > 5) { canBeDouble = true; } } catch (Exception) { } if (tableDetailsArray[i][1].Substring(0, 3) == "int" && tableDetailsArray[i][5] == "auto_increment" && Convert.ToInt32(getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))) > 0) { param += " AND `" + tableDetailsArray[i][0] + "` LIKE @" + tableDetailsArray[i][0]; cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))); isIdRunId = true; } else if (tableDetailsArray[i][1].Substring(0, 3) == "int" && tableDetailsArray[i][5] != "auto_increment" && Convert.ToInt32(getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))) > -1) { param += " AND `" + tableDetailsArray[i][0] + "` LIKE @" + tableDetailsArray[i][0]; cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))); } else if ((tableDetailsArray[i][1] == "date" || tableDetailsArray[i][1].Substring(0, 4) == "date") && getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])).ToString() != "1/1/0001 12:00:00 AM") { if (entity.dateCondition == null) { param += " AND DATE(`" + tableDetailsArray[i][0] + "`) LIKE @" + tableDetailsArray[i][0]; cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropDateValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))); } else { try { if (entity.dateCondition[tableDetailsArray[i][0]] != null) { param += " AND (DATE(`" + tableDetailsArray[i][0] + "`) " + entity.dateCondition[tableDetailsArray[i][0]][0] + " @" + tableDetailsArray[i][0] + "1" + " AND @" + tableDetailsArray[i][0] + "2" + ")"; cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0] + "1", entity.dateCondition[tableDetailsArray[i][0]][1]); cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0] + "2", entity.dateCondition[tableDetailsArray[i][0]][2]); } else { param += " AND DATE(`" + tableDetailsArray[i][0] + "`) LIKE @" + tableDetailsArray[i][0]; cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropDateValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))); } } catch (Exception) { } } } else if (canBeDouble && tableDetailsArray[i][1].Substring(0, 6) == "double" && Convert.ToDouble(getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))) > 0) { if (entity.doubleCondition == null) { param += " AND `" + tableDetailsArray[i][0] + "` = @" + tableDetailsArray[i][0]; cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))); } else { try { if (entity.doubleCondition[tableDetailsArray[i][0]] != null) { param += " AND `" + tableDetailsArray[i][0] + "` " + entity.doubleCondition[tableDetailsArray[i][0]] + " @" + tableDetailsArray[i][0]; cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))); } else { param += " AND `" + tableDetailsArray[i][0] + "` = @" + tableDetailsArray[i][0]; cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))); } } catch (Exception) { } } } else if (tableDetailsArray[i][5] != "auto_increment" && getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])) != null && getPropType(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])) != "System.Double" && getPropType(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])) != "System.Int32" && (getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0])).ToString() != "1/1/0001 12:00:00 AM")) { param += " AND `" + tableDetailsArray[i][0] + "` LIKE @" + tableDetailsArray[i][0]; cmd.Parameters.AddWithValue("@" + tableDetailsArray[i][0], getPropValue(entity, getPropertyNameByColumnName(tableDetailsArray[i][0]))); } } if (entity.ManualQueries != null) { param += " " + entity.ManualQueries; } if (!isIdRunId) { param = " AND `id` != '0'" + param; } param = param.Substring(4); if (entity.OrderBy != null) { param += " ORDER BY " + entity.OrderBy; /*param += " ORDER BY @orderBy @orderType"; cmd.Parameters.AddWithValue("@orderBy", entity.OrderBy); cmd.Parameters.AddWithValue("@orderType", entity.OrderType);*/ } if (entity.RowsCount < 1 && entity.LimitStart > -1) { param += " LIMIT @limitStart , @limitEnd"; cmd.Parameters.AddWithValue("@limitStart", entity.LimitStart); cmd.Parameters.AddWithValue("@limitEnd", entity.LimitEnd); } /*if(entity.OrderBy != null) { param += " ORDER BY @orderBy @orderType"; cmd.Parameters.AddWithValue("@orderBy", entity.OrderBy); cmd.Parameters.AddWithValue("@orderType", entity.OrderType); } if(entity.LimitStart > -1) { param += " LIMIT @limitStart , @limitEnd"; cmd.Parameters.AddWithValue("@limitStart", entity.LimitStart); cmd.Parameters.AddWithValue("@limitEnd", entity.LimitEnd); }*/ SELECT_TEXT += param + ";"; //SELECT_TEXT += param + (entity.RowsCount > 0 ? ") AS cou" : "") + ";"; cmd.CommandText = SELECT_TEXT; cmd.Prepare(); DataSet dataSet = new DataSet(); new MySqlDataAdapter(cmd).Fill(dataSet); connection.Close(); return dataSet; } catch (Exception) { connection.Close(); return null; } } [/PHP] mcn me code eke for loop eka iwara nowenna hethuwa poddak kiyapanko :dull: [/SIZE] [/QUOTE]
Insert quotes…
Verification
Nawa warak dahaya keeyada? (Namaya wadi kireema dahaya)
Post reply
Top
Bottom