Home > Net >  Everybody to help!" System. The Data. SqlClient. SqlDataAdapter "does not include the"
Everybody to help!" System. The Data. SqlClient. SqlDataAdapter "does not include the"

Time:11-13

using System;
using System.Collections.Generic;
Using System. Linq;
Using System. The Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;
Using System. The Data. SqlClient.
Using System. The Data;



Public partial class Default34: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
BindData ();
}
}
Public void BindData ()
{
SqlConnection con=new SqlConnection (" Server=. User ID=sx782369; The Pwd=123456; The DataBase=sx782369 ");
SqlDataAdapter SCD=new SqlDataAdapter (" select * from course2 ", con);
DataSet ds=new DataSet();
SCD. The Fill (ds);
GridView1. The DataSource=ds;
GridView1. DataBind ();
GridView1. DataKeyNames=new string [] {" id "};
}
Protected void GridView1_roweditinf (object sender, GridViewEditEventArgs e)
{
GridView1. EditIndex=e.N ewEditIndex;
DataBind ();
}
Protected void GridView1_RowUpdating (object sender, GridViewUpdateEventArgs e)
{
String bccdID=GridView1. DataKeys [" e.R owIndex]. Value. The ToString ();
String bccdName=((TextBox) (GridView1 Rows [" e.R owIndex]. Cells [1]. The Controls [0])). The Text. The ToString ();
String bccdPrice=((TextBox) (GridView1 Rows [" e.R owIndex]. Cells. [2] Controls [0])). The Text. The ToString ();
String upsql="update course2 set brccdName='" + bccdName +"', brccdPrice='" + bccdPrice + "' where id='" + bccdID + "' ";
Bool update=excesql (upsql);
If (update)
{
Response. Write (" & lt; script> Alert (' modify success ~) & lt;/script>" );
GridView1. EditIndex=1;
BindData ();
}
}
Public bool excesql (string STRSQL)
{
String strcon=@ "Server=. User ID=sx782369; The Pwd=123456; The DataBase=sx782369 ";
SqlConnection conn=new SqlConnection (strcon);
SqlDataAdapter SCD=new SqlDataAdapter (STRSQL, conn);
Try
{
If (conn. State==System. Data. ConnectionState. Closed)
{
Conn. The Open ();
}
SCD. ExecuteNonQuery ();
return true;
}
Catch
{
return false;
}
The finally
{
Conn. Close ();
}
}
}
SCD. ExecuteNonQuery (); It is always wrong,
CS1061: "System. The Data. SqlClient. SqlDataAdapter" does not include the definition of "ExecuteNonQuery", and couldn't find the acceptable type for "System. The Data. SqlClient. SqlDataAdapter" of the first parameter to the extension method "ExecuteNonQuery" (whether or not the lack of a using directive or assembly reference?)

CodePudding user response:

SCD. ExecuteNonQuery ();
Change
The DataTable TAB=new DataTable ();
SCD. The fill (TAB);

CodePudding user response:

This class does not provide this method, you why dedication, I don't want to compile all through

CodePudding user response:

C # 2 set of operational database component
1. The SqlDataAdapter cooperate the dataset
2. The SqlCommand directly use SQL statements to add and delete,
ExecuteNonQuery belong to SqlCommand
This probably try can jump over it, there are many online encapsulated sqlhelper, use them directly,

CodePudding user response:

Is the method of SqlCommand command inside the

CodePudding user response:

SqlDataAdapter adapter is

CodePudding user response:

 
SqlDataAdapter SCD=new SqlDataAdapter (STRSQL, conn);


==& gt;

 
SqlCommand SCD=new SqlCommand (STRSQL, conn);

CodePudding user response:

Thank you, head very dizzy on the day didn't see the code dialed the wrong number, the second day found, when I was looking for trouble

CodePudding user response:

Just learn think DataAdataper convenient, only its corresponding DataTable adaptation is a relational database,

We never dataadapters now, we have almost no DataTable, and similar ExecuteNonQuery such demand is actually should develop a set of useful SqlHelper simple framework,

CodePudding user response:

Posting period of our code
 the CreateCommand ($" update/agent set organization code=@ j, [name]=@ t, state [team]=@ z, long rates [team]=@ f the where Id=@ Id ") 
SetParam (" j ", this.Com mand. GetValue (" code "))
SetParam (" t ", this.Com mand. GetValue (" team name "))
SetParam (" z ", this.Com mand. GetValue (" team status "))
SetParam (" f ", this.Com mand. GetValue (" team long rates "))
SetParam (" id ", this.Com mand. GetValue (" Id "))
ExecuteNonQuery ();


ADO.NET themselves to encapsulate the extension function, become a SQLHelper, can make it better use, more clear,

For example (simplified version, actually we SQLHelper to deal with the different database such as Oracle)
 public static DbCommand command SetParam (this DbCommand command CMD, string paramName, object paramValue) 
{
The switch (paramValue)
{
In case a DateTime dt:
If (dt) Year & lt; 1753)
ParamValue=https://bbs.csdn.net/topics/new DateTime (1753, 1, 1);
break;
A case of null:
ParamValue=https://bbs.csdn.net/topics/DBNull.Value;
break;
}
Var p=CMD. CreateParameter ();
P.P arameterName=paramName;
P.V alue=https://bbs.csdn.net/topics/paramValue;
CMD. The Parameters. The Add (p);
Return CMD.
}
through a similar definition, you can let the c # language is more suitable for writing habits,