Sql server if the row exist it update if the row new won't update

I am
working with Asp.net and C# and using SQl Server, I insert a row in one plase and works fine but when I try to update the same row it woudn't do anything, I
try to update an existing row it works with the same code but not if I just
insert new row.
my code as
below:
String companyName = txCompany.Text.ToString();
SqlConnection con =
new
SqlConnection(conString);
SqlCommand cmd =
new
SqlCommand("INSERT
INTO DocUp (CompanyName)VALUES (@CompanyName)", con);
cmd.Parameters.AddWithValue("@CompanyName", companyName);
try
con.Open();
cmd.ExecuteNonQuery();
catch (Exception
er)
Response.Write("<script language='javascript'>alert('Connection Problem On Insert');</script>");
finally
con.Close();
string strQuery =
"UPDATE DocUp SET 
QuoteFileName=@QuoteFileName, ContentType=@ContentType, QuoteFileData=@Data WHERE CompanyName=@Company";
SqlCommand cmd =
new
SqlCommand(strQuery);
cmd.Parameters.Add("@QuoteFileName",
SqlDbType.VarChar).Value = filename;
cmd.Parameters.Add("@ContentType",
SqlDbType.VarChar).Value =
"application/pdf";
cmd.Parameters.Add("@Data",
SqlDbType.Binary).Value = bytes;
cmd.Parameters.Add("@Company",
SqlDbType.VarChar).Value = companyName;
InsertUpdateData(cmd);
private
Boolean InsertUpdateData(SqlCommand
cmd)
String strConnString = System.Configuration.ConfigurationManager
.ConnectionStrings["S7V001_11022014ConnectionString1"].ConnectionString;
  SqlConnection con =
new
SqlConnection(strConnString);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
con.Open();
cmd.ExecuteNonQuery();
return
true;
      catch (Exception
ex)
Response.Write(ex.Message);
return
false;
finally
con.Close();
con.Dispose();

Please use the  "Insert code block" button to insert *readable* code blocks 
try{
con.Open();
cmd.ExecuteNonQuery();
return true;
You have not shared what query/functions that you are using to insert data. Please share. 
Also it looks like more like a .Net related questions, (and if you agree,  ) I would recommend posting the question in .Net forum
http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral
Also I would recommend you to read "How to ask questions in Technical Forums" from the below link
Satheesh
My Blog |
How to ask questions in technical forum

Similar Messages

  • System keeps looking for a 'server' that does not exist. Is says the old name of my Airport Extreme. Clicking it away (4x) it gets through.

    System keeps looking for a 'server' that does not exist. Is says the old name of my Airport Extreme. Clicking it away (4x) finally  gets through.

    Other weirdness to report: my neighbor upstairs appears to have a Linksys router network on channel 6. My AEBS is on channel 1 so there shouldn't be interference... but according to iStumbler sometimes the signal leaps to 64000 (keep in mind my own Airport never tops 60)! Is that potentially the problem?
    Might it be possible that your neighbor just acquired a 802.11n (pre-N) wireless router recently?
    802.11n effectively increases capacity by doubling the number of Wi-Fi radios and increasing the number of antennas used to push signals out of those radios. 802.11n splits a data frame into multiple pieces. It then transmits these pieces in parallel using multiple radios that are attached to multiple antennas. These antennas blast out signals from virtually the same vantage point – scattering the signals everywhere.
    You may find the following ZDNet article interesting: http://blogs.zdnet.com/Ou/?p=247
    Even if he did not, and you are on good terms, you might want to ask if he can temporarily turn off his wireless, or, at least, reduce the signal strength to see if that will help in your situation.

  • SQL ENTERPRISE: The edition of Reporting Services that you are using requires that you use local SQL Server relational databases for report data sources and the report server database

    The error below makes absolutely no sense! I'm using Enterprise Core...yet I'm being told I can't use remote data sources:
    w3wp!library!8!03/05/2015-19:08:48:: i INFO: Catalog SQL Server Edition = EnterpriseCore
    w3wp!library!8!03/05/2015-19:08:48:: e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.OperationNotSupportedException: , Microsoft.ReportingServices.Diagnostics.Utilities.OperationNotSupportedException: The feature: "The edition of Reporting
    Services that you are using requires that you use local SQL Server relational databases for report data sources and the report server database." is not supported in this edition of Reporting Services.;
    Really? This totally contradicts the documentation found here:
    https://msdn.microsoft.com/en-us/library/ms157285(v=sql.110).aspx
    That article says remote connections are completely supported.
    ARGH! Why does this have to be so difficult to setup?!?

    Hi jeffoliver1000,
    According to your description, you are using Enterprise Core edition and you are prompted that you can’t use remote data sources.
    In your scenario, we neither ignore your point nor be doubt with what you say. But actually we have met the case before that even though the SQL Server engine is Enterprise but the reporting services is still standard. So I would recommend you to find the
    actual edition of reporting services you are using. You can find Reporting Services starting SKU in the Reporting Service logs ( default location: C:\Program Files\Microsoft SQL Server\<instance name>\Reporting Services\LogFiles). For more information,
    please refer to the similar thread below:
    https://social.technet.microsoft.com/Forums/en-US/f98c2f3e-1a30-4993-ab41-acbc5014f92e/data-driven-subscription-button-not-displayed?forum=sqlreportingservices
    By the way, have you installed the other SQL Server edition before?
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider,

    An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider,
    error: 40 - Could not open a connection to SQL Server)

    An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named
    Pipes Provider, error: 40 - Could not open a connection to SQL Server)
    Hello,
    Make sure your SQL Server service is started.
    Make sure TCP\IP and names pipes protocol is enabled
    Make sure you have made an exception in firewall for SQL Server connection
    Make sure SQL Server browser service is enabled
    Make sure you connect with correct name hostname\instance name for named instance,MSSQLSERVER for default instance and Hotname\SQLEXPRESS for express edition.
    Please make sure you use port no when connecting to SQL server listeing on different port (hostname\instance ,portno)
    http://blogs.msdn.com/sql_protocols/archive/2006/09/30/SQL-Server-2005-Remote-Connectivity-Issue-TroubleShooting.aspx
    Hope this helps
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • I am unable to see following SQL Server Analysis Services in central admin services after the SQL 2014 power pivot installations

    I am unable to see following SQL Server Analysis Services  in central admin services after the SQL 2014 power pivot installations
    Ravi

    Hi Ravi,
    Per my knowledge, there is no Analysis Service in SharePoint.
    After running the SQL 2014 setup to install PowerPivot for SharePoint, you need to open the PowerPivot for SharePoint 2013 Configuration tool in Central Admin Server and configure PowerPivot for SharePoint.
    After that, you will see new Service Application called "Default PowerPivot Service Application" in Central Administration.
    If you have other WFE servers, then you need to install the PowerPivot Add-In on all the other servers in the SharePoint farm.
    More references:
    http://sridharbabuk.blogspot.jp/2013/02/installing-configuring-analysis-service.html
    http://msdn.microsoft.com/en-us/library/jj219067.aspx
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • HT201365 How can the iMessages and FaceTime be activated with this new ISO 7 update? When I enter my Apple ID & password it won't do anything. Says waiting for activation!! Help!

    How can the iMessages and FaceTime be activated with this new ISO 7 update? When I enter my Apple ID &amp; password it won't do anything. Says waiting for activation!! Help!

    Hi there,
    You may find the troubleshooting steps in the article below helpful.
    iOS: Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/ts4268
    -Griff W.

  • Regarding ReCreating Catalog in SQL Server 2005 which was existing in SQL Server 2000

    Hello
    I was using SQL SERVER 2000 ... In one table I've created FULL TEXT SEARCHING ( Full text catalog along with full text indexing)
    Now we had to install our db in SQL SERVER 2005 standard edition. But while taking script it gave me two lines like:
    if (select DATABASEPROPERTY(DB_NAME(), N'IsFullTextEnabled')) <> 1
    exec sp_fulltext_database N'enable'
    GO
    if not exists (select * from dbo.sysfulltextcatalogs where name = N'DEV_CAS_DiagnosisCatalog')
    exec sp_fulltext_catalog N'DEV_CAS_DiagnosisCatalog', N'create'
    GO
    so I used this in the new db creation script...
    But I couldn't get where it actually is in SQL SERVER 2005 standard edition.
    and also plz help how should we create if it doesn't exist...
    What could be the problem....
    Thanks In advance

    if (select DATABASEPROPERTY(DB_NAME(), N'IsFullTextEnabled')) <> 1
    exec sp_fulltext_database N'enable'
    GO
    if not exists (select * from dbo.sysfulltextcatalogs where name = N'DEV_CAS_DiagnosisCatalog')
    exec sp_fulltext_catalog N'DEV_CAS_DiagnosisCatalog', N'create'
    GO
    sp_fulltext_catalog [ @ftcat= ] 'fulltext_catalog_name' ,
    [ @action= ] 'action'
    [ , [ @path= ] 'root_directory' ]
    Full-text catalog and index data is stored in files created in a full-text catalog directory(not on SSMS). The full-text catalog directory is created as a sub-directory of the directory specified in
    @path or in the server default full-text catalog directory if
    @path is not specified. The name of the full-text catalog directory is built in a way that guarantees it will be unique on the server. Therefore, all full-text catalog directories on a server can share the same path.
    Refer the path column by running the below query. full text catalog file is created under the root directory by default if the path is not specified.
    select * from dbo.sysfulltextcatalogs where name = N'DEV_CAS_DiagnosisCatalog'
    Refer
    http://technet.microsoft.com/en-us/library/ms189520(v=sql.90).aspx
    Regards, RSingh

  • Try to do my first XML Schema in SQL Server 2012 Mangement Studio(SSMS2012)-How to execute the xsd and xml files in SSMS2012?

    Hi all,
    I learmed the basic stuff of XML, DTD, DOM, etc. long time ago. Now, I came back to resume my XML journey and try to learn the XML Schemas, XPath and XQuery. I have Microsoft SQL Server 2012 Management Studio (SSMS2012) in our computer network. From
    Page 221 of the old Book "Beginning XML 2nd Edition" written by David Hunter, et.al., (published by Wrox), I copied the name5.xsd and name5.xml :
    <?xml version="1.0"?>
    <schema xmlns=http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.wrox.com/name" xmlns:target="http://www.wrox.com/name"
    elementFormDefault="qualified">
    <element name="name">
    <complexType>
    <sequence>
    <element name="first" type="string"/>
    <element name="middle" type="string"/>
    <element name="last" type="string"/>
    </sequence>
    </complexType>
    </element>
    </schema>
    <?xml version="1.0"?>
    <name
    xmlns=http://www.wrox.com/name"
    xmlns:xsi="http://www.wrox.org/2001XMLSchema-instance"
    xsi:schemaLocation="http://www.wrox.com/name name5.xsd"
    title="Mr.">
    <first>John</first>
    <middle>Frizgerald</middle>
    <last>Doe</last>
    </name>
    How can I execute these two files in my SSMS2012 for doing my first XML Schema trial?
    Please kindly help, advise and respond.
    Thanks in advance,
    Scott Chang

    Hi Eric Zhang, Thanks for your nice response.
    1) I saw the CREATE XML SCHEMA COLLECTION (Transact-SQL) and tried  its first example "Create XML schema collection in the database" in my SQL Server 2012 Management Studio (SSMS2012):
    -- Create a sample database in which to load the XML schema collection.
    -- Copied this set of code stsments from Microsoft Library (ms176009)
    -- ColesMS12_20a.sql (saved in C:/Documents/SQL Server Management Studio)
    -- 19 March 2015 1145 AM
    CREATE DATABASE SampleDB
    GO
    USE SampleDB
    GO
    CREATE XML SCHEMA COLLECTION ManuInstructionsSchemaCollection AS
    N'<?xml version="1.0" encoding="UTF-16"?>
    <xsd:schema targetNamespace="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"
    xmlns ="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
    <xsd:complexType name="StepType" mixed="true" >
    <xsd:choice minOccurs="0" maxOccurs="unbounded" >
    <xsd:element name="tool" type="xsd:string" />
    <xsd:element name="material" type="xsd:string" />
    <xsd:element name="blueprint" type="xsd:string" />
    <xsd:element name="specs" type="xsd:string" />
    <xsd:element name="diag" type="xsd:string" />
    </xsd:choice>
    </xsd:complexType>
    <xsd:element name="root">
    <xsd:complexType mixed="true">
    <xsd:sequence>
    <xsd:element name="Location" minOccurs="1" maxOccurs="unbounded">
    <xsd:complexType mixed="true">
    <xsd:sequence>
    <xsd:element name="step" type="StepType" minOccurs="1" maxOccurs="unbounded" />
    </xsd:sequence>
    <xsd:attribute name="LocationID" type="xsd:integer" use="required"/>
    <xsd:attribute name="SetupHours" type="xsd:decimal" use="optional"/>
    <xsd:attribute name="MachineHours" type="xsd:decimal" use="optional"/>
    <xsd:attribute name="LaborHours" type="xsd:decimal" use="optional"/>
    <xsd:attribute name="LotSize" type="xsd:decimal" use="optional"/>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>' ;
    GO
    -- Verify - list of collections in the database.
    select *
    from sys.xml_schema_collections
    -- Verify - list of namespaces in the database.
    select name
    from sys.xml_schema_namespaces
    -- Use it. Create a typed xml variable. Note collection name specified.
    DECLARE @x xml (ManuInstructionsSchemaCollection)
    GO
    --Or create a typed xml column.
    CREATE TABLE T (
    i int primary key,
    x xml (ManuInstructionsSchemaCollection))
    GO
    -- ////The following code statements are not used in order to create SampleDB
    -- Clean up
    ---DROP TABLE T
    ---GO
    ---DROP XML SCHEMA COLLECTION ManuInstructionsSchemaCollection
    ---Go
    ---USE Master
    ---GO
    ---DROP DATABASE SampleDB
    It worked and I got the following results:
    1 4 NULL sys 2009-04-13 12:59:13.390 2012-02-10 20:16:02.097
    65536 1 NULL ManuInstructionsSchemaCollection 2015-03-19 11:47:17.660 2015-03-19 11:47:17.660
    http://www.w3.org/2001/XMLSchema
    http://schemas.microsoft.com/sqlserver/2004/sqltypes
    http://www.w3.org/XML/1998/namespace
    http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions
    But, I don't undertand (i) what SCHEMA COECTION is, (ii) what <xsd:schema targetNamespace=.....</xsd:complexType> are, (iii) How I can specify my "project specific" schema in the Microsoft SCHEMA COLLECTION to check my xml file.
    2) I dived in the XQuery programmimng in SSMS2012 in the last few weeks. I used the examles of Ad-Hoc XML File Query by Seth Delconte (in
    httpS://www.simple-talk.com/content/print.aspx?article=1756) in my SSMS2012. They worked. But I don't understand the (i) Importing XML data using a function, (ii) Using the XQuery contans()
    function to find substrings, (iii)Efficiency comparisons in the article.
    Please kindly help me in enlightening me to resolve the difficulties listed in 1) and 2).
    Thanks,
    Scott Chang

  • Running an SQL Server Agent Job to execute a package but the job FAILS on Connections

    I have created a package which basically imports data from one database to another, The database where it collects the data from the job is failing on connecting reporting the following message:
    Source: ****** Connection manager "Source - *****"     Description: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E4D.  An OLE DB record is available.  Source: "Microsoft
    OLE DB Provider for SQL Server"  Hresult: 0x80040E4D  Description: "Login failed for user '*ConnectionONE*'.".  End Error  Error: 2015-02-18 11:36:04.94     Code: 0xC020801C    
    Source: Data Flow Task Get Revenue Data [1]     Description: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.  The AcquireConnection method call to the connection manager "Source - *****" failed with error
    code 0xC0202009.
    The package runs fine if executed within the package but fails from the SQL Agent Job.
    NB * is to hide confidential data. *ConnectionONE* is the database which the package is attempting to get data from.
    Completely puzzled on what to do as i have tried reading other forumns but they dont seem to be helping.
    Any Help would be great thankyou!

    That is because package is set to "EncryptSensitiveWithUserKey". Please change that to "EncryptSensitiveWithPassword" and the provide password to protect sensitive data.
    More information
    here.
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • The feature: "The edition of Reporting Services that you are using requires that you use local SQL Server relational databases for report data sources and the report server database." is not supported in this edition of Reporting Services.

    Hello all,
    I have SQL express 2014 advance edition installed ..
    and i am connecting SQl server 2008 r2 instance which is in network 
    while creating datasource in Reportserver which has Express installed ..
    got this error ..
    please help me how to connect to remote server
    Dilip Patil..

    Error message says it all.
    With SQL Express, Data source should be local SQL DB.
    With SQL Enterprise, Standard, BI edition, you can create Data soruce which are hosted on other servers.
    Please refer similar thread:
    https://social.msdn.microsoft.com/Forums/en-US/c0468e3f-bad7-47a7-a695-75c13762280a/the-feature-the-edition-of-reporting-services-that-you-are-using-requires-that-you-use-local-sql?forum=sqlreportingservices
    Cheers,
    Vaibhav Chaudhari
    [MCTS],
    [MCP]

  • Can't connect to MSSQL-server via SQL Server Management Studio. Noone else can utilize the server either

    Suddenly the mSSQL-server has stopped working, and the application doesn't have any connection to it.
    Also, I cant connect locally via SQL Server Management Studio.
    Any ideas on where to start?
    Have SQL Server 2008 R2

    Try DAC first:
    http://technet.microsoft.com/en-us/library/ms178068(v=sql.105).aspx
    If that fails, go to Configuration Manager and restart the server.
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • SQL Server XQuery: Sequence Expression - What is @x in the code statement of DECLARE @x xml; ? What is N in the code statement of SET @x = N ' '; ?

    Hi all,
    I did the basic stuff of T-SQL long time ago. I dive in to do the SQL Server XQuery programming. I saw the following set of code statements from a tutotial website:
    DECLARE @x xml;
    SET @x = N'';
    SELECT @x.query('(1,2,(10,11,12,13,14,15)),-6');
    1) What is @x in the code statement of DECLARE @x xml;? What is N in the code statement of SET @x = N ' '? 
    2) Is the N in the code statement of SET @x = N ' '; absobutally necessary in the SQL Server XQuery programming?  From XQuery Language Reference of SQL Server 2012 Books Online, I saw the following set of code statements:
    DECLARE @x XML
    SET @x = '<a/>'
    SELECT @x.query('if (/a[1]) then "true" else "false"')
    go
    I wonder why there is no N in the code statement of the XQuery Language Reference?
    Please kindly help, clarify my confusions and answer my questions mentioned above.
    Thanks in advance,
    Scott Chang

    @x is a variable with xml data type. An N prefix stands for the string in Unicode. The N is not necessary in the SQL Server XQuery programming if the values of the element or attribute in the xml are not in an international language.
    A Fan of SSIS, SSRS and SSAS

  • Sql Server 2012:Full Text Catalog taking up all the disk space

    We have created full text catalog and index for a pretty large table. The column on which the index is being created has a datatype of varchar(max). The problem started as soon as we started populating the catalog. It almost grew to 835GB and Population
    status stuck to "Processing Notification". I think is status code 9 which corresponds with
    the "Change tracking" status in the SQL. It gets stuck in this status almost for ever.
    Is there a way to deal with this huge catalog size, may be shrink it or move it to a different location. 
    Is switching off Change Tracking going to improve the situation.
    Any help regarding this will be highly appreciated.
    Thanks,
    Saikat

    Hello,
    There could be considerable amount of indexes on that catalog and the effect of the merge over them. Try the index size property of
    the following function:
    http://msdn.microsoft.com/en-US/library/ms190370(v=sql.110).aspx
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • SQL Server 2008 R2 - Connection from multiple sources makes the database drop.

    Hey,
    I have a database being accesses from multiple sources - IIS and WPF application.
    Once a user enters the website(which is connected to the database through a Connection String), The WPF application stops its communication with the database, or vise versa.
    The problem being solved once I restart the IIS service or the SQL instance service.
    Thanks in advanced.
    Nir.

    Hello Nir,
    Thank you for your question. I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 
    Thank you for your understanding and support.
    If you have any feedback on our support, please click
    here.
    Regards,
    Elvis Long
    TechNet Community Support

  • I have firefox16.0 and would like to update to the most recent version (19). But my Firefox won't update

    Hi there
    I've got windows vista on my computer, and am using Firefox 16.0. Have been for a while now, ever since it was installed a year ago or so.
    The thing is, Firefox won't update to the latest version (currently version 19 I believe), neither automatically or manually. I've tried everything, including using the "help" function. The window only says it's Firefox 16.0, but when I click on "update", the page just refresh and that's it, nothing else happens. I've checked all other settings, and it looks like all the right boxes are ticked, including "update Firefox automatically".
    Coming to think about it, on my wife's computer, we are always told about new updates for Firefox. On this one, no update alert of any sorts since it was installed a while ago (and again, all the right boxes being ticked)
    Please can anybody help? Should i reinstall Firefox altogether?
    Thanks for your help
    Frankie

    see this:
    [[Update Firefox to the latest version|Update Firefox to the latest version]]

Maybe you are looking for

  • Measure execution time with PowerShell

    What would be the best way to accomplish following: 1. Get start time and write it to variable 2. Do something 3. Get end time and measure how long it taked from start to end and store the result in variable I would need the result be in format like

  • Changing payment proposal variant

    Hi, I need to add "invoice reference" and "user ID" to a payment proposal variant. I went to the variant in SE38 but was not able to find any field to add the above to two fields Not sure how should I do this? can anyone please guide

  • Restricted key figure

    HI, can any body explain me what is the difference between Restricted key Figure and the filter option in BEX reporting.

  • Grant execute on package

    Dear all, I have a package that has procedures related to other. I want to grant some users execute on some of those procedures, and others execute on other procedures. Say create package holiday_pkg as procedure ask_holiday(emp_no in number, period

  • Do I need to create an account??

    Hello, may sound strange but when I go to iChat, preferences, add account i get the 'account setup' dialog box. I enter my MobileMe credentials but there is a 'Get an iChat account...' push button displayed. Is this just a standard button or do I nee