Connect to the database COREDB, insert an article into the table mybbs. Table MyBBS is as follows: if exists (select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Mybbs]') And ObjectProperty (ID, n'susertable ') = 1) DROP TABLE [DBO]. [mybbs] Go
Create Table [DBO]. [Mybbs] ([ID] [Bigint] Identity (1, 1) Not Null, [Title] [CHAR] (160) Collate Chinese_PRC_CI_AS NULL, [Author] [char] (20) Collate Chinese_PRC_CI_AS NULL , [Date_of_Created] [datetime] NULL, [Abstract] [char] (480) COLLATE Chinese_PRC_CI_AS NULL, [Content] [ntext] COLLATE Chinese_PRC_CI_AS NOT NULL) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GOTextBox1, TextBox2 respectively, to provide a user input of the title Two TextBoxs in the article content, check and save the article into the database.
private void Button1_Click (object sender, System.EventArgs e) {SqlConnection coreDB = new SqlConnection (); coreDB.ConnectionString = "workstation id = /" GQA-ERIC-LV / "; packet size = 4096; integrated security = SSPI;" "Data source = /" gqa-eric-lv / "; persist security info = false; initial catalog = coreb"; string title = textbox1.text; string content = textBox2.text; if (title.trim () == "| || Content.trim () ==" ") Return; String MySelectQuery = @" Insert Into Mybbs (Title, Content) VALUES ('" Title ",' " Content ") "; SQLCommand MyCommand = New SQLCOMMAND (MySelectQuery, Coredb); CoredB.Open (); SqlDataReader MyReader = MyCommand.executeReader (); MyReader.close (); Coredb.Close ();}