Home > Net >  Do with VS GirdView application really can't find something wrong great god save code and all t
Do with VS GirdView application really can't find something wrong great god save code and all t

Time:11-27

This is my problem:

This is my code:
using System;
using System.Collections.Generic;
Using System. The Data;
Using System. The Data. SqlClient.
Using System. Linq;
Using System. The Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;

The namespace data control advanced application
{
Senior public partial class data control applications: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
if (! Whether IsPostBack)//verification page postback
{
GridViewBind ();//call the binding data method
}
}
Public void GridViewBind ()
{
Using (SqlConnection sqlCon=new SqlConnection ())
{
SqlCon. The ConnectionString="server=DESKTOP - VJO357M \ \ ME2020; Uid=sa; The PWD=19980608; The database=1 ";
String SqlStr="select * from movie data";//define the SQL statement
SqlCon. The Open ();//open the database connection
SqlDataAdapter da=new SqlDataAdapter (SqlStr sqlCon);//instantiate the SqlDataAdapter object
The DataSet ds=new DataSet ();//instantiate the data set DataSet
Da. The Fill (ds);//the data into the DataSet
GridView1. The DataSource=ds;//bind the DataList control
GridView1. DataBind ();//perform binding
Da. The Dispose ();//release resources
}
}

Protected void GridView1_PageIndexChanging (object sender, GridViewPageEventArgs e)
{
GridView1. PageIndex=e.N ewPageIndex;//set the new page
controlsGridViewBind ();//to bind data
}

Protected void GridView1_RowEditing (object sender, GridViewEditEventArgs e)
{
//set the GridView control edit item index to select the current index
GridView1. EditIndex=e.N ewEditIndex;
//data binding
GridViewBind ();
}



Protected void GridView1_RowUpdating (object sender, GridViewUpdateEventArgs e)
{
//edit the key field value
String name=movie GridView1. DataKeys [" e.R owIndex]. Value. The ToString ();
//the contents of a text box input
String cumulative gross=((TextBox) (GridView1. Rows [" e.R owIndex]. Cells [1]. The Controls [0])). The Text. The ToString ();
Director of string=((TextBox) (GridView1 Rows [" e.R owIndex]. Cells. [2] Controls [0])). The Text. The ToString ();
Starring string=((TextBox) (GridView1 Rows [" e.R owIndex]. Cells [3]. The Controls [0])). The Text. The ToString ();
String release area=((TextBox) (GridView1. Rows [" e.R owIndex]. Cells. [4] Controls [0])). The Text. The ToString ();
String of countries and regions=((TextBox) (GridView1. Rows [" e.R owIndex]. Cells. [5] Controls [0])). The Text. The ToString ();
String distribution companies=((TextBox) (GridView1. Rows [" e.R owIndex]. Cells. [6] Controls [0])). The Text. The ToString ();
Type string=((TextBox) (GridView1 Rows [" e.R owIndex]. Cells. [7] Controls [0])). The Text. The ToString ();
//define the SQL statement
String sqlStr="update film data set total box office='" + +" cumulative box office, director=' "+ +" director ", starring='starring "+ +"', release area='" + + "release area, countries and regions='" + countries and regions, "', distribution companies='" issued + company +"', type='" + + "type' where movie name=" + film;
SqlConnection myConn=new SqlConnection (" server=DESKTOP - VJO357M \ \ ME2020; Uid=sa; The PWD=19980608; The database=1 ");
MyConn. The Open ();
//executing SQL statements
SqlCommand myCmd=new SqlCommand (sqlStr myConn);
MyCmd. ExecuteNonQuery ();
MyCmd. The Dispose ();
MyConn. Close ();
//set editor row index
GridView1. EditIndex=1;
//rebind
GridViewBind ();
}
Protected void GridView1_RowCancelingEdit (object sender, GridViewCancelEditEventArgs e)
{
//set the editor of the GridView control index of 1 item, or cancel editing
GridView1. EditIndex=1;
//data binding
GridViewBind ();
}
}
}

CodePudding user response:

Already hint, SQL statement, may use the Chinese brackets brackets, or have extra, please check

CodePudding user response:

You do the variable name in Chinese no problem, please look at skull ache, you can put sqlStr with out the database to see

CodePudding user response:

Problem is not the code, but the line of Sql query statements contained ExecuteNonQuery, or SqlConnection string

CodePudding user response:

A breakpoint on your Update SQL statements, see what the joining together of SQL statements is, should be a SQL statement has a mistake

CodePudding user response:

To add N before Chinese field

CodePudding user response:

Is the stitching is something wrong with the SQL

CodePudding user response:

See ID I just came in with a smile, in fact, I want to go to bed early, but the old BUG, can not sleep,

Try add [field name], [movie name], take a look at single quotes or without Chinese punctuation, take SQL statements to the database, can you run?
  • Related