请教,如何将数据库技术和对象技术很好的结合起来。最好能给个例子。谢谢
请教,如何将数据库技术和对象技术很好的结合起来。最好能给个例子。谢谢
private void upBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(NewsKindList.SelectedIndex > 0)
{
int nSelectedIndex = NewsKindList.SelectedIndex;
String id = NewsKindList.SelectedItem.Value.ToString();
SqlConnection myConnection = new SqlConnection(GlobalDB.DataBaseDB.ConnectionString);
String cmdText = "UPDATE NewsKinds SET KindOrder = KindOrder - 1 WHERE NewsKindID = " + id;
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
cmdText = "UPDATE NewsKinds SET KindOrder = KindOrder + 1 WHERE KindOrder = (SELECT KindOrder FROM NewsKinds WHERE NewsKindID = " + id + ") AND NewsKindID <> " + id;
myCommand = new SqlCommand(cmdText,myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
BindNewsKindData();
NewsKindList.SelectedIndex = Math.Max(0,(nSelectedIndex - 1));
}
}
{
if(NewsKindList.SelectedIndex > 0)
{
int nSelectedIndex = NewsKindList.SelectedIndex;
String id = NewsKindList.SelectedItem.Value.ToString();
SqlConnection myConnection = new SqlConnection(GlobalDB.DataBaseDB.ConnectionString);
String cmdText = "UPDATE NewsKinds SET KindOrder = KindOrder - 1 WHERE NewsKindID = " + id;
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
cmdText = "UPDATE NewsKinds SET KindOrder = KindOrder + 1 WHERE KindOrder = (SELECT KindOrder FROM NewsKinds WHERE NewsKindID = " + id + ") AND NewsKindID <> " + id;
myCommand = new SqlCommand(cmdText,myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
BindNewsKindData();
NewsKindList.SelectedIndex = Math.Max(0,(nSelectedIndex - 1));
}
}
private void downBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(NewsKindList.SelectedIndex < (NewsKindList.Items.Count - 1))
{
int nSelectedIndex = NewsKindList.SelectedIndex;
String id = NewsKindList.SelectedItem.Value.ToString();
SqlConnection myConnection = new SqlConnection(GlobalDB.DataBaseDB.ConnectionString);
String cmdText = "UPDATE NewsKinds SET KindOrder = KindOrder + 1 Where NewsKindID = " + id;
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
cmdText = "UPDATE NewsKinds SET KindOrder = KindOrder -1 WHERE KindOrder = (SELECT KindOrder FROM NewsKinds WHERE NewsKindID = " + id + ") AND NewsKindID <> " + id;
myCommand = new SqlCommand(cmdText,myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
BindNewsKindData();
NewsKindList.SelectedIndex = Math.Min((NewsKindList.Items.Count - 1),(nSelectedIndex + 1));
}
}
{
if(NewsKindList.SelectedIndex < (NewsKindList.Items.Count - 1))
{
int nSelectedIndex = NewsKindList.SelectedIndex;
String id = NewsKindList.SelectedItem.Value.ToString();
SqlConnection myConnection = new SqlConnection(GlobalDB.DataBaseDB.ConnectionString);
String cmdText = "UPDATE NewsKinds SET KindOrder = KindOrder + 1 Where NewsKindID = " + id;
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
cmdText = "UPDATE NewsKinds SET KindOrder = KindOrder -1 WHERE KindOrder = (SELECT KindOrder FROM NewsKinds WHERE NewsKindID = " + id + ") AND NewsKindID <> " + id;
myCommand = new SqlCommand(cmdText,myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
BindNewsKindData();
NewsKindList.SelectedIndex = Math.Min((NewsKindList.Items.Count - 1),(nSelectedIndex + 1));
}
}