|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
SQLServer是基于服务器端的中型的数据库,可以适合大容量数据的应用,在功能上管理上也要比Access要强得多。在处理海量数据的效率,后台开发的灵活性,可扩展性等方面强大。这段代码我没收拾过,但愿哪位收拾一下从头贴下去
usingSystem;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.Globalization;
usingSystem.Windows.Forms;
usingSystem.ComponentModel;
usingSystem.Data.SqlClient;
namespaceComboBoxInDataGrid
{
publicclassForm2:System.Windows.Forms.Form
{
///<summary>
///Requireddesignervariable.
///</summary>
privateSqlDataAdaptersqlDA;
privateSqlCommandsqlSelectStudent;
privateSqlCommandsqlInsertStudent;
privateSqlCommandsqlUpdateStudent;
privateSqlCommandsqlDeleteStudent;
privateSystem.ComponentModel.Containercomponents=null;
privatestringStrSQL;
privateSqlConnectionsqlConn;
privateDataSet_StudentDS;
privateDataTable_CourseDT;
privateDataGridTableStyleGridTableStyle;
privateSystem.Windows.Forms.ButtonbtnUpdate;
privateSystem.Windows.Forms.ButtonbtnMoveFirst;
privateSystem.Windows.Forms.ButtonbtnMovePrevious;
privateSystem.Windows.Forms.ButtonbtnMoveNext;
privateSystem.Windows.Forms.ButtonbtnMoveLast;
privateSystem.Windows.Forms.DataGriddataGrid1;
privateSystem.Windows.Forms.Labellabel1;
privateCurrencyManagerobjStudentCM;
publicForm2()
{
//
//RequiredforWindowsFormDesignersupport
//
InitializeComponent();
//
//TODO:AddanyconstructorcodeafterInitializeComponentcall
//
}
///<summary>
///Cleanupanyresourcesbeingused.
///</summary>
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#regionWindowsFormDesignergeneratedcode
///<summary>
///RequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththecodeeditor.
///</summary>
privatevoidInitializeComponent()
{
this.sqlUpdateStudent=newSystem.Data.SqlClient.SqlCommand();
this.sqlConn=newSystem.Data.SqlClient.SqlConnection();
this.sqlDA=newSystem.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteStudent=newSystem.Data.SqlClient.SqlCommand();
this.sqlInsertStudent=newSystem.Data.SqlClient.SqlCommand();
this.sqlSelectStudent=newSystem.Data.SqlClient.SqlCommand();
this.btnMoveLast=newSystem.Windows.Forms.Button();
this.dataGrid1=newSystem.Windows.Forms.DataGrid();
this.btnUpdate=newSystem.Windows.Forms.Button();
this.btnMoveNext=newSystem.Windows.Forms.Button();
this.btnMoveFirst=newSystem.Windows.Forms.Button();
this.btnMovePrevious=newSystem.Windows.Forms.Button();
this.label1=newSystem.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
//sqlUpdateStudent
//
this.sqlUpdateStudent.CommandText=@"UPDATEStudentSETSNo=@SNo,SName=@SName,Course=@CourseWHERE(SNo=@Original_SNo)AND(Course=@Original_CourseOR@Original_Course1ISNULLANDCourseISNULL)AND(SName=@Original_SNameOR@Original_SName1ISNULLANDSNameISNULL);SELECTSNo,SName,CourseFROMStudentWHERE(SNo=@Select_SNo)";
this.sqlUpdateStudent.Connection=this.sqlConn;
this.sqlUpdateStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@SNo",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,false,((System.Byte)(0)),((System.Byte)(0)),"SNo",System.Data.DataRowVersion.Current,null));
this.sqlUpdateStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@SName",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"SName",System.Data.DataRowVersion.Current,null));
this.sqlUpdateStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Course",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"Course",System.Data.DataRowVersion.Current,null));
this.sqlUpdateStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Original_SNo",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,false,((System.Byte)(0)),((System.Byte)(0)),"SNo",System.Data.DataRowVersion.Original,null));
this.sqlUpdateStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Original_Course",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"Course",System.Data.DataRowVersion.Original,null));
this.sqlUpdateStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Original_Course1",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"Course",System.Data.DataRowVersion.Original,null));
this.sqlUpdateStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Original_SName",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"SName",System.Data.DataRowVersion.Original,null));
this.sqlUpdateStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Original_SName1",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"SName",System.Data.DataRowVersion.Original,null));
this.sqlUpdateStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Select_SNo",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,false,((System.Byte)(0)),((System.Byte)(0)),"SNo",System.Data.DataRowVersion.Current,null));
//
//sqlConn
//
this.sqlConn.ConnectionString="datasource=localhost;initialcatalog=myData;persistsecurityinfo=False;userid="+
"sa;workstationid=NWAD-SJALLI;packetsize=4096";
//
//sqlDA
//
this.sqlDA.DeleteCommand=this.sqlDeleteStudent;
this.sqlDA.InsertCommand=this.sqlInsertStudent;
this.sqlDA.SelectCommand=this.sqlSelectStudent;
this.sqlDA.TableMappings.AddRange(newSystem.Data.Common.DataTableMapping[]{
newSystem.Data.Common.DataTableMapping("Table","Student",newSystem.Data.Common.DataColumnMapping[]{
newSystem.Data.Common.DataColumnMapping("SNo","SNo"),
newSystem.Data.Common.DataColumnMapping("SName","SName"),
newSystem.Data.Common.DataColumnMapping("Course","Course")})});
this.sqlDA.UpdateCommand=this.sqlUpdateStudent;
//
//sqlDeleteStudent
//
this.sqlDeleteStudent.CommandText="DELETEFROMStudentWHERE(SNo=@SNo)AND(Course=@CourseOR@Course1ISNULL"+
"ANDCourseISNULL)AND(SName=@SNameOR@SName1ISNULLANDSNameISNULL)";
this.sqlDeleteStudent.Connection=this.sqlConn;
this.sqlDeleteStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@SNo",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,false,((System.Byte)(0)),((System.Byte)(0)),"SNo",System.Data.DataRowVersion.Original,null));
this.sqlDeleteStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Course",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"Course",System.Data.DataRowVersion.Original,null));
this.sqlDeleteStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Course1",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"Course",System.Data.DataRowVersion.Original,null));
this.sqlDeleteStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@SName",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"SName",System.Data.DataRowVersion.Original,null));
this.sqlDeleteStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@SName1",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"SName",System.Data.DataRowVersion.Original,null));
//
//sqlInsertStudent
//
this.sqlInsertStudent.CommandText="INSERTINTOStudent(SNo,SName,Course)VALUES(@SNo,@SName,@Course);SELECTSN"+
"o,SName,CourseFROMStudentWHERE(SNo=@Select_SNo)";
this.sqlInsertStudent.Connection=this.sqlConn;
this.sqlInsertStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@SNo",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,false,((System.Byte)(0)),((System.Byte)(0)),"SNo",System.Data.DataRowVersion.Current,null));
this.sqlInsertStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@SName",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"SName",System.Data.DataRowVersion.Current,null));
this.sqlInsertStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Course",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,true,((System.Byte)(0)),((System.Byte)(0)),"Course",System.Data.DataRowVersion.Current,null));
this.sqlInsertStudent.Parameters.Add(newSystem.Data.SqlClient.SqlParameter("@Select_SNo",System.Data.SqlDbType.VarChar,50,System.Data.ParameterDirection.Input,false,((System.Byte)(0)),((System.Byte)(0)),"SNo",System.Data.DataRowVersion.Current,null));
//
//sqlSelectStudent
//
this.sqlSelectStudent.CommandText="SELECTSNo,SName,CourseFROMStudent";
this.sqlSelectStudent.Connection=this.sqlConn;
//
//btnMoveLast
//
this.btnMoveLast.Anchor=(System.Windows.Forms.AnchorStyles.Bottom|System.Windows.Forms.AnchorStyles.Left);
this.btnMoveLast.Font=newSystem.Drawing.Font("MicrosoftSansSerif",8.25F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(0)));
this.btnMoveLast.Location=newSystem.Drawing.Point(128,264);
this.btnMoveLast.Name="btnMoveLast";
this.btnMoveLast.Size=newSystem.Drawing.Size(32,24);
this.btnMoveLast.TabIndex=5;
this.btnMoveLast.Text="|>";
this.btnMoveLast.Click+=newSystem.EventHandler(this.btnMoveLast_Click);
//
//dataGrid1
//
this.dataGrid1.AlternatingBackColor=System.Drawing.Color.WhiteSmoke;
this.dataGrid1.Anchor=(((System.Windows.Forms.AnchorStyles.Top|System.Windows.Forms.AnchorStyles.Bottom)
|System.Windows.Forms.AnchorStyles.Left)
|System.Windows.Forms.AnchorStyles.Right);
this.dataGrid1.BackColor=System.Drawing.Color.Gainsboro;
this.dataGrid1.BackgroundColor=System.Drawing.Color.Beige;
this.dataGrid1.CaptionBackColor=System.Drawing.Color.Blue;
this.dataGrid1.CaptionForeColor=System.Drawing.Color.Yellow;
this.dataGrid1.DataMember="";
this.dataGrid1.ForeColor=System.Drawing.Color.Navy;
this.dataGrid1.GridLineColor=System.Drawing.Color.Chocolate;
this.dataGrid1.HeaderBackColor=System.Drawing.Color.CadetBlue;
this.dataGrid1.HeaderFont=newSystem.Drawing.Font("MicrosoftSansSerif",10F,System.Drawing.FontStyle.Bold);
this.dataGrid1.HeaderForeColor=System.Drawing.Color.Brown;
this.dataGrid1.Location=newSystem.Drawing.Point(16,8);
this.dataGrid1.Name="dataGrid1";
this.dataGrid1.PreferredColumnWidth=-1;
this.dataGrid1.SelectionBackColor=System.Drawing.Color.Brown;
this.dataGrid1.SelectionForeColor=System.Drawing.Color.Aqua;
this.dataGrid1.Size=newSystem.Drawing.Size(512,224);
this.dataGrid1.TabIndex=0;
实现规模效益。与传统的用户拥有硬件软件所有权和使用权以及传统的应用服务商提供一对一的服务模式不同,ASP拥有应用系统所有权,用户拥有使用权,应用系统集中放在ASP的数据中心中,集中管理,分散使用,以一对多的租赁的形式为众多用户提供有品质保证的应用技术服务,实现规模效益。 |
|