Created
January 16, 2013 18:42
-
-
Save BjornFridal/4549634 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (SqlConnection cn = new SqlConnection("***connection string***")) { | |
cn.Open(); | |
SqlCommand cmd = new SqlCommand("SELECT id, contentNodeId, dataInt, dataNtext FROM cmsPropertyData WHERE (propertytypeid = ***id***) AND (dataNtext IS NOT NULL) ORDER BY contentNodeId", cn); | |
SqlDataReader dr = cmd.ExecuteReader(); | |
while (dr.Read()) { | |
int dataInt; | |
int nodeId; | |
if (int.TryParse(dr["id"].ToString(), out nodeId) && int.TryParse(dr["dataNtext"].ToString(), out dataInt)) { | |
// print the dataInt (where the new id will be stored) | |
// and the dataNtext (where the old id from Media Picker With Preview) | |
Response.Write(String.Format("int: {0}, text: {1}<br/>", dr["dataInt"].ToString(), dr["dataNtext"].ToString())); | |
// do the update | |
// uncomment this part | |
// when ready to do the update | |
// using (SqlConnection cn2 = new SqlConnection("***connection string***")) { | |
// cn2.Open(); | |
// SqlCommand UpdateCmd = new SqlCommand("UPDATE cmsPropertyData SET dataInt = " + dataInt + " WHERE id = " + nodeId, cn2); | |
// UpdateCmd.ExecuteNonQuery(); | |
// cn2.Close(); | |
// } | |
} | |
else { | |
// the dataNtext couldn't be parsed as an int | |
// maybe some old data is in here from an earlier | |
// data type, lets print it and have a look | |
Response.Write(String.Format("<strong>Huh?</strong> - id: {0}, text: {1}<br/>", dr["id"].ToString(), dr["dataNtext"].ToString())); | |
} | |
} | |
dr.Close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment