c# - I'm trying to edit a datatable on a SQL server and i keep getting an error about either not accepting a keyword or not connecting due to a timeout -


i need able view table , select row table , edit field in row project i'm working on. right i'm using proof of concept program figure out how works can implement real thing. first error server not recognizing keyword "provider"

protected void changebutton_click(object sender, eventargs e) {     using (sqlconnection conn = new sqlconnection(system.configuration.configurationmanager.connectionstrings["connectionstring"].connectionstring))     {         sqlcommand cmd = new sqlcommand();         cmd.connection = conn;         cmd.commandtext = "update devtesting set teststr = @teststr, teststr2 = @teststr2, teststr3 = @teststr3, testnum = @testnum personid = @personid";         cmd.commandtype = commandtype.text;           string strpersonid = gridview1.rows[1].cells[1].text;         string strteststr1 = "aerhtsm";            cmd.parameters.add("@teststr", sqldbtype.nvarchar, 50).value = strteststr1;         conn.open();         cmd.executenonquery();     }      gridview1.editindex = -1;     bindgridview();   }  private void bindgridview() {      using (sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["sqlserver2005dbconnectionstring"].tostring()))     {         dataset grid1 = new dataset();         string strselectcmd = "select teststr, teststr2, teststr3, testnum gridview1";         sqldataadapter da = new sqldataadapter(strselectcmd, conn);         conn.open();         da.fill(grid1, "gridview1");         dataview dvperson = grid1.tables["gridview1"].defaultview;         gridview1.datasource = grid1;         gridview1.databind();     } } 

the other error i'm getting connection keeps timing out when code reaches conn.open(); in changebutton method. can please explain i'm doing wrong. heres copy of web.config file in case need it.

     <?xml version="1.0" encoding="utf-8"?>      <configuration>    <configsections>     <section name="entityframework" type="system.data.entity.internal.configfile.entityframeworksection, entityframework, version=5.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"  requirepermission="false" />    </configsections>    <connectionstrings>     <add name="defaultconnection" connectionstring="data source=(localdb)\v11.0;initial catalog=aspnet-webapplication11-20130731142716;integrated security=sspi;attachdbfilename=|datadirectory|\aspnet-webapplication11-20130731142716.mdf"   providername="system.data.sqlclient" />      <add name="testconnectionstring" connectionstring="provider=sqlncli11;data source=hqsql;integrated security=sspi;initial catalog=bg_backup"   providername="system.data.oledb" />       <add name="connectionstring" connectionstring="provider=sqlncli11;data source=hqsql;integrated security=sspi;initial catalog=bg_backup"   providername="system.data.oledb" />      </connectionstrings>       <system.web> <compilation debug="true" targetframework="4.5" /> <httpruntime targetframework="4.5" /> <pages>   <namespaces>     <add namespace="system.web.optimization" />   </namespaces>   <controls>     <add assembly="microsoft.aspnet.web.optimization.webforms" namespace="microsoft.aspnet.web.optimization.webforms" tagprefix="webopt" />   </controls> </pages> <authentication mode="forms">   <forms loginurl="~/account/login.aspx" timeout="2880" /> </authentication> <profile defaultprovider="defaultprofileprovider">   <providers>     <add name="defaultprofileprovider" type="system.web.providers.defaultprofileprovider, system.web.providers, version=1.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" connectionstringname="defaultconnection" applicationname="/" />   </providers> </profile> <membership defaultprovider="defaultmembershipprovider">   <providers>     <add name="defaultmembershipprovider" type="system.web.providers.defaultmembershipprovider, system.web.providers, version=1.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" connectionstringname="defaultconnection" enablepasswordretrieval="false" enablepasswordreset="true" requiresquestionandanswer="false" requiresuniqueemail="false" maxinvalidpasswordattempts="5" minrequiredpasswordlength="6" minrequirednonalphanumericcharacters="0" passwordattemptwindow="10" applicationname="/" />   </providers> </membership> <rolemanager defaultprovider="defaultroleprovider">   <providers>     <add name="defaultroleprovider" type="system.web.providers.defaultroleprovider, system.web.providers, version=1.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" connectionstringname="defaultconnection" applicationname="/" />   </providers> </rolemanager> <sessionstate mode="inproc" customprovider="defaultsessionprovider">   <providers>     <add name="defaultsessionprovider" type="system.web.providers.defaultsessionstateprovider, system.web.providers, version=1.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" connectionstringname="defaultconnection" />   </providers> </sessionstate>   </system.web>  <entityframework>   <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework">        <parameters>      <parameter value="v11.0" />      </parameters>       </defaultconnectionfactory>     </entityframework>       </configuration> 

ok here image of error when push button overwrite part of datatable. tried remedie solution on own , got similar error in second image.

the connectionstring key in connectionstring section of web.config used sqlclient.sqlconnection specify use providername="system.data.oledb". should change providername="system.data.sqlclient" oledb client cannot understand syntax.

then update command uses 5 parameters, add 1 parameters collection. error, after opening of connection.

then in bindgridview use connectionstring not defined anywhere, select statement here refers table named gridview, suspect have mistyped correct name of table (the 1 used in update command called devtesting )

for timeout problem should add exception message connected timeout


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -