Getting Identity After Updating

Mar 4, 2006

Hi..


Code:

Update Table
Set Field=Field+1
Where Customer='pette.n'



after running this query how can I get identity number (ID)

after inserting a record, the command below gives the last identity
SELECT IDENT_CURRENT('Table')

is there a function like this for updating records

P.S. the only thing I can use in query is Customer value

View 3 Replies


ADVERTISEMENT

Updating Identity Column

Sep 18, 2007

Please excuse my ignorance.  I've researched this and it appears I am asking to do something that is ridiculous, so please let me know what is wrong with my design (or my brain).  I'd like to update an ID number in a table.  It is an identity column.  In my solution I'm adding a lot of new entries into my table and deleting old ones.  Call me anal, but It's driving me nuts that my ID numbers are growing so large so quickly and that I have so many unused ID's.  If you were to look over my data ID's they would be something like 1,3,45,78,88,89,103,140,219.  What I'm trying to do is renumber my data so that my data currently at say ID# 1067 can be moved to the unused ID#2, etc.  So I either need a way to update an Identity column...or I need a way find the lowest unused number among a list of ID's.  So is there anyway to achieve what I am trying to do?  I see this guy had my same OCD issue (without a solution) :-(

View 3 Replies View Related

Updating IDENTITY Column

May 2, 2000

Do anyone knows if there is a way that I can manually update the value in an IDENTITY column?

Thanks

View 2 Replies View Related

IDENTITY Problems Updating ZipCode Table

Aug 16, 2004

I am having problems updating my zip code table that contains zip, city, state, long, lat, ect..

I have the latest CSV file, I tried to use the import wizard in SQL Server 2000 Enterprise Manager.
I set the ID field as <ignore> and specified the appropriate columns for the rest of the data matching from CSV to already designed and working zip code table. Also I checked the box that said "Delete Rows in Destination Table" as well as "Enable Identity Insert" was checked

I ran the wizard, and now I have empty table and it will not insert any records because the error said that the identity column can not accept NULL.

What do I do? I am not updating the identify column so Is it telling me it can't insert NULL into ID?

Any suggestions...

Thanks,
Lito

View 3 Replies View Related

Interview Question-How To Identity Existing Data For Updating In SSIS?

Feb 26, 2008

I have met the interview question, I provide answer like the following from my experience. I don't know it is correct or need to supplement. Thank you for help.

Question: How to identity existing data for updating in SSIS?

Answer:
If you have the same key columns such as primary key or business key, you just use them to identify existing records from data source to destination.

If you use different key columns between data source and destination, you can create permanent link table which will store business key for data source and destination, and you can compare records from linking table when you update data.

View 1 Replies View Related

Updating A Table By Both Inserting And Updating In The Data Flow

Sep 21, 2006

I am very new to SQL Server 2005. I have created a package to load data from a flat delimited file to a database table. The initial load has worked. However, in the future, I will have flat files used to update the table. Some of the records will need to be inserted and some will need to update existing rows. I am trying to do this from SSIS. However, I am very lost as to how to do this.

Any suggestions?

View 7 Replies View Related

Last GASP On Insert Row In Table With Identity Field, And Get New Identity Back ?

Jul 9, 2006

While I have learned a lot from this thread I am still basically confused about the issues involved.

.I wanted to INSERT a record in a parent table, get the Identity back and use it in a child table. Seems simple.

To my knowledge, mine would be the only process running that would update these tables. I was told that there is no guarantee, because the OLEDB provider could write the second destination row before the first, that the proper parent-child relationship would be generated as expected. It was recommended that I create my own variable in memory to hold the Identity value and use that in my SSIS package.

1. A simple example SSIS .dts example illustrating the approach of using a variable for identity would be helpful.

2. Suppose I actually had two processes updating these tables, running at the same time. Then it seems the "variable" method will also have its problems. Is there a final solution other than locking the tables involved prior to updating them or doing something crazy like using a GUID for the primary key!

3. We have done the type of parent-child inserts I originally described from t-sql for years without any apparent problems. (Maybe we were just lucky.) Is the entire issue simply a t-sql one or does SSIS add a layer of complexity beyond t-sql that needs to be addressed?



TIA,



Barkingdog

View 10 Replies View Related

Insert Row In Table With Identity Field, And Get New Identity Back

Jun 30, 2006

I want to insert a new record into a table with an Identity field and return the new Identify field value back to the data stream (for later insertion as a foreign key in another table).

What is the most direct way to do this in SSIS?



TIA,



barkingdog



P.S. Or should I pass the identity value back in a variable and not make it part of the data stream?

View 12 Replies View Related

T-SQL (SS2K8) :: How To Update Identity Column With Identity Value

Jan 25, 2015

I have table of three column first column is an ID column. However at creation of the table i have not set this column to auto increment. Then i have copied 50 rows in another table to this table then set the ID column values to zero.

Now I have changed the ID column to auto increment seed=1 increment=1 but the problem is i couldn't figure out how to update this ID column with zero value set to each row with this auto increment values so the ID column would have values from 1-50. Is there a away to do this?

View 6 Replies View Related

Identity...I Need To Get The Last (or Highest Number In Identity Column)...

Sep 19, 2005

Ok,I just need to know how to get the last record inserted by the highestIDENTITY number. Even if the computer was rebooted and it was twoweeks ago. (Does not have to do with the session).Any help is appreciated.Thanks,Trint

View 2 Replies View Related

Problem In Using Sqlbulkcopy To Insert Data From Datatable(no Identity Column) Into Sql Server Table Having Identity Column

Jun 19, 2008

Hi,
I am having problem in bulk update of a sql server table haning identity column from a datatable( has no identity column) using sqlbulkcopy. I tried several approaches, but it does not show any error nor is the table getting updated. But the identity value seems to getting increased every time.
thanks.
varun

View 6 Replies View Related

How To Use Identity On Non-identity Column (with Concurrence)

Aug 1, 2014

I'm working with a third-party database (SQL Server 2005) and the problem here is the following:

- There are a bunch of ETL processes that needs to insert rows on a table (let's call this table T) and at the same time, an ERP (owner of T) is up and running (reading, updating and inserting on T).

- The PK of T is an Integer.

Today all ETL processes uses (select max(ID) + 1 from T) to insert new rows, so just picture the scenario. It is a mess! Everyday they get duplicate key error when 2 or more concurrent processes are trying to insert a row (with the max) at the same time.

Considering that I can't change the PK, what is the best approach to solve this problem?

To sum up:

* I need to have processes in parallel inserting on T

* I can't change anything on T

* The PK is NOT an Identity

View 4 Replies View Related

Transact SQL :: Alter Non Identity Column To Identity Column

Aug 12, 2009

when i alter non identity column to identity column using this Query alter table testid alter column test int identity(1,1) then i got this error message Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'identity'.

View 2 Replies View Related

Updating

Aug 24, 2007

I am trying to make a stored procedure in my website for updating an address:1 CREATE PROCEDURE dbo.UPDATE
2 (
3 @add NVarchar(50),
4 @cit NVarchar(50),
5 @state NVarchar(50),
6 @zip NVarchar(50),
7 @CNum int
8 )
9
10 UPDATE table_name
11 AppAdd = @add, AppCity = @cit, AppState = @state, AppZip = @zip
12 WHERE CertNum = @CNum When I try to save it it give me an error: Incorrect syntax near keyword 'UPDATE'Must declare scalar variable '@add'
 

View 1 Replies View Related

I Am New To Asp.net And I Need Help With Updating

Feb 24, 2008

Hi, I'm new to ASP.Net quite new to C# (My first attempt at a database website) and am trying to get a button to add "1" to "int" value called "Comments" a each time its pressed basically counting each time a comment is added. I also only wnat it to affect the row where "ModID" in my database is equal to the query string "ModID" I'm using on the page. I cannot find any tutorials so this is my best guess so far. This is probably a Noobie type stupid question but I'm stuck.  This is the code I have so far for my Button_Click event:  protected void Button_Click(object sender, EventArgs e){        SqlDataSource CommentCountDataSource = new SqlDataSource();        CommentCountDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["Main_Site_DatabaseConnectionString1"].ToString();        CommentCountDataSource.UpdateCommandType = SqlDataSourceCommandType.Text;        CommentCountDataSource.SelectCommand = "SELECT (ModID, DateTimeLastComment, Comments) FROM Mods";        CommentCountDataSource.UpdateCommand = "UPDATE Mods SET (DateTimeLastComment=@DateTimeLastComment, Comments=@Comments) WHERE ModID=@ModID"; //How do i get the Where to use the query string info?                CommentCountDataSource.UpdateParameters.Add("DateTimeLastComment", DateTime.Now.ToString());                CommentCountDataSource.UpdateParameters.Add("Comments", "10");     //"10" is just a value to test I'll change this to add "1" once I figure how.        CommentCountDataSource.Update();}  Sorry if I'm using the wrong lingo but as I say I'm new. If my code is a mile off then please can you send me in the right direction of some code that works.Thanks in advance if anyone can help me. Cheers,Alan

View 5 Replies View Related

Updating

Apr 13, 2008

guys can anyone know whats wrong with my syntax? I always get this error: ERROR [07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.This is the syntax: Protected Sub btnupd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnupd.Click        Dim pwing, pblood, pcolor, plcolor, pmark, pbdate, pstat, premark, ppefr, pstyle As Object        Dim sql As String        Dim y As New Object        y = GVh.SelectedDataKey(0)        pwing = txtwingb.Text        pblood = txtblood.Text        pcolor = txtcolor.Text        plcolor = txtlcolor.Text        pmark = txtmark.Text        pbdate = ddday.SelectedValue & "-" & Ddmonth.SelectedValue & "-" & ddyear.SelectedValue        pstat = txtstat.Text        premark = txtremark.Text        sql = "UPDATE [broodhen]"        sql = sql & " SET bwing = '" & pwing & "',"        sql = sql & " bloodlines = '" & pblood & "',"        sql = sql & " color = '" & pcolor & "',"        sql = sql & " lcolor = '" & plcolor & "',"        sql = sql & " mark = '" & pmark & "',"        sql = sql & " bday = '" & pbdate & "',"        sql = sql & " status = '" & pstat & "',"        sql = sql & " remarks = '" & premark & "'"        sql = sql & " WHERE(bwing = '@wwing')"        DShen.UpdateCommand = sql        DShen.Update()        MView.SetActiveView(GView)    End SubThat is from my aspx.vb file and for the .aspx my datasource:<asp:SqlDataSource ID="DShen" runat="server"             ConnectionString="<%$ ConnectionStrings:CSD %>"             ProviderName="<%$ ConnectionStrings:CSD.ProviderName %>"             SelectCommand="SELECT * FROM [broodhen]" > </asp:SqlDataSource>  Note: I select records from a gridview to edit. i can delete, insert, select but i cant update. please help... tnx.

View 3 Replies View Related

Updating A DB

Jul 28, 2005

I am trying to update a SQL Server DB via my ASP.NET application with the following SqlCommand:

UPDATE    StudentCourses
SET              SC_Active = 0
WHERE     (UT_ID IN (@UT_IDs)) AND (CO_ID = @CO_ID)

@UT_IDs in populated from a StringBuilder object with the following:
354,284,305,281,308,351,439,355,306,282

When I run the application to update the DB, I get the error:
System.FormatException: Input string was not in a correct format.

If I change @UT_IDs to:
354
if works.

Can anyone explain this behaviour?

Cheers,
ocann

View 1 Replies View Related

Updating

Feb 8, 2001

I am a DBA who is moving in the direction of minor database design. I have gone through the steps to get my tables normalized, and I am ready to get them set up so they will update from table to table. How do I set this up? I know SQL does not cascade like Access, so how is this done? From what I have read (Robert Vieira's book) I should use triggers? Any help would be appreciated. Dallas

View 1 Replies View Related

Updating

Aug 30, 2005

I have a query that updates

strSQL = "UPDATE customers SET "
strSQL &= "entryid = '" & strtheEntryid & " ' "
strSQL &= "WHERE id =1 "
right now in table id is my primary key field it increments by 1, I want to say get first record instead of saying id = 1, how to do that?

View 2 Replies View Related

Help With Updating Changes

Nov 29, 2007

I have some code to hack in c#..
I have a database and when a form (C#) is loaded a copy of the table is made in a DataTable object. The form has a list box showing just the one column of info from the local DataTable.
On the form it is possible to change a record, delete a record and add a record. These are all done in the local table.

The question, how do i send these changes back to the database. Currently it deletes the lot and copies all the local table values in. How do only do the affected row, UPDATE, INSERT etc

View 1 Replies View Related

Updating With ADO.net

Mar 25, 2008

Hey

I have an ASP application that uses a stored procedure and ADO.net to update a sql server data file. The problem is I know the code is working, I don't have any errors with the ADO, no exceptions are caught. I can use the same basic code to insert a record using a different procedure. It is the update procedure that does not carry through.

So, I know I have a connection, the procedure works using the query builder directly so the procedure works, but when I run the code, I get no errors and no update to the datafile. I am not even sure how to trouble shoot this since I don't have an error to look up.

C# Code:-------------

private void UpdateIssue()
{
DateTime date = new DateTime();
date = Convert.ToDateTime(this.txtDate.Text);

//edit record in HelpDeskIssuesTbl here.

SqlConnection con = new SqlConnection("Data Source...");
SqlCommand comUpdateTicket = new SqlCommand("sp_UpdateHelpDeskIssues", con);
comUpdateTicket.CommandType = CommandType.StoredProcedure;
comUpdateTicket.Parameters.Add("@IssueID", this.GridView1.SelectedIndex.ToString());
comUpdateTicket.Parameters.Add("@EmpID", this.ddlEmployee.SelectedValue.ToString());
comUpdateTicket.Parameters.Add("@Date", date.ToShortDateString());
comUpdateTicket.Parameters.Add("@StatusID", this.ddlStatus.SelectedValue.ToString());

try
{
con.Open();
comUpdateTicket.ExecuteNonQuery();

}
catch (Exception ex)
{
this.lblMessage.Text = "Data save error: " + ex.Message.ToString();
this.pnlMessage.Visible = true;
}
finally
{
con.Close();
}
}

----------------------------------------------------
dbo.sp_UpdateHelpDeskIssues

(
@IssueID int,
@EmpID int,
@Date datetime,
@StatusID int
)

AS
UPDATE HelpDeskIssuesTbl
SET EmployeeID = @EmpID, IssueDate = @Date, IssueStatusID = @StatusID
WHERE (IssueID = @IssueID)
RETURN

Like I said the Stored Procedure does work when I run it directly in Visual Studio. I have double checked all the params and they all match up unless I am missing something.

Please send help! Thanks.

View 2 Replies View Related

SCD Not Updating

Jul 17, 2007

Hi gurus,


My feeling with the SCD component is not that very solid. I have the feeling that the behavior of the insert/update strategy is not always correct an working.
I will describe two problems that i encounter.

1. My destination table contains records with the value ''. Cause i don't want '' ( 2 single quotes) in our DWH i update the view that is the source with a case statement that changes the '' to NULL. But when i run the packages the '' values are not update with the NULL values. When i delete the destination table and run the package, the records are inserted with the NULL value as expected. Anyone who has experienced this problem?

2. When i create a new table and run the package so the destination table gets filled with records the SCD will insert alle records (for example 100). When i start the run directly after the first run, all records are updated instead of doing nothing what it should do cause all records exists.

Anyone who can give me some feedback?

with regards, Arthur

View 15 Replies View Related

Updating A Row

Jun 27, 2006

Hi

I come from a Unix backgound and used Informix ISQL quite frequently.

I have a row that contains a compund field 'cust_and_date' and contains a value of C0003 32656

I want to write an update statement that will amend the C0003 to C00009 but leaves the 32656 as is.

I tried the following:-

update scheme.slitemm set substring(cust_and_date,1,8) = 'C00009'

This returned a syntax error

Any help gratefully received



View 5 Replies View Related

Updating A SqlDataSource

Dec 12, 2006

I am looking for a way to update a sqldatasource what I have is a ASP Wizard applicationstep oneis a dataview with the select ability it displays an ID and Namein step two what i want it to do is take the ID from step ones select and put that into the where clause so I have select * from table where id = step1selectedID

Code:

View 1 Replies View Related

Updating A Column In SQL

Dec 13, 2006

I am trying to update a users status from Pending to either Approved or Rejected.  I created the following handers to update me db by I keep getting a syntax error. What am I doing wrong? public partial class admin_beta : System.Web.UI.Page{    protected void ApproveButton_Click(object sender, EventArgs e)    {        SqlConnection conn = new SqlConnection("Data Source=TECATE;Initial Catalog=subscribe_mainSQL; User Id=maindb Password=$$ricardo; Integrated Security=SSPI");        SqlCommand cmd = new SqlCommand("UPDATE [main] ([status]) VALUES (@status)", conn);        conn.Open();        cmd.Parameters.AddWithValue("@status", "Approved");        int i = cmd.ExecuteNonQuery();        conn.Dispose();    }    protected void DenyButton_Click(object sender, EventArgs e)    {        SqlConnection conn = new SqlConnection("Data Source=TECATE;Initial Catalog=subscribe_mainSQL; User Id=maindb Password=$$ricardo; Integrated Security=SSPI");        SqlCommand cmd = new SqlCommand("UPDATE [main] ([status]) VALUES (@status)", conn);        conn.Open();        cmd.Parameters.AddWithValue("@status", "Rejected");        int i = cmd.ExecuteNonQuery();        conn.Dispose();    }}

View 4 Replies View Related

Sql Datasource Not Updating

Mar 6, 2007

I have this web store that I have been creating.  When a customer goes to check out, he has to log in, then he is redirected to a page where he can view/add/or edit shipping and billing address.  I have based all the sql statements on the profile username, adding records and retrieving them works just fine.  When I go to change something in the info it uses an sql statement that updates based on "Where AccountUserName = @AccountUserName", I have @AccountUserName set to Profile("Username").  Keep in mind this works fine for adding new or bring up current records.  I even put in code in the updated event for the sql data source to post a msgbox telling me how many rows were affected, it says 1 even though I dont see any change in the data.   What am I doing wrong here, it's driving me nuts, its just a very simple update. 

View 2 Replies View Related

Updating The Database

Mar 7, 2007

Hi All:

Appreciate your efforts in answering queries of so many newbees!I hope to find answering my query..I
have created a logon screen to which i have also given the option of
changing the password ... Now below is the code for updating the new
password given by the user ....Imports System.Data.SqlClient     Dim con As New SqlConnection("server=sys2;initial catalog=kris;integrated security=SSPI")    Dim cmd As New SqlCommand("select * from u_login", con)      Dim dr As SqlDataReader    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load    End Sub    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click        con.Open()        dr = cmd.ExecuteReader        While dr.Read()            If dr(0) = txtEmail.Text And dr(1) = txtoldpwd.Text Then                Dim NewPwdStr As String = txtnewpwd.Text                Dim OldPwdStr As String = txtoldpwd.Text                Dim sqlstr As String = "Update U_Login set pwd = ('" & NewPwdStr & "') Where pwd = '" & OldPwdStr & "'"                Dim cmd1 As New SqlCommand("sqlstr", con)                                        cmd1.ExecuteNonQuery()                Response.Write(" Password Changed ... Please login again")            End If        End While        dr.Close()        con.Close()    End Sub The above code although doesnt
throw any error however it shows a blank screen and doesnt even update
the new password. Can you plz help me understand what could possibly be
wrong in my code n why is that am getting the blank screen. Your help will be highly appreciated!Thanks,Brandy

View 6 Replies View Related

SQL Server Is Not Updating

Jun 13, 2007

I am in a fix where I cant seem to update my records.  I am trying to follow a template for an Event calendar and cant seem to get the update page working correctly.   basically the update on the server never occurs but the message is still returned.  Very confused is it my stored procedure?
Imports System.Data
Imports System.Data.SqlClientPartial Class _Default
Inherits System.Web.UI.PageProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Bind()
End SubSub Bind()Using Conn As New SqlConnection("Data Source=WINSERV;Initial Catalog=EventCalendar;User ID=antonio;Password=xxxx;User Instance=False")
Conn.Open()Dim cmd As New SqlCommand("sp_GetEvent", Conn)
cmd.CommandType = Data.CommandType.StoredProcedure
Dim ParameterID As New SqlParameter("@Event_ID", SqlDbType.Int, 4)ParameterID.Value = Request.QueryString("Event_ID")
cmd.Parameters.Add(ParameterID)Dim myDataReader As SqlDataReader
myDataReader = cmd.ExecuteReader
myDataReader.Read()txtapeDate.Text = myDataReader.Item("apeDate")
txtapEvent.Text = myDataReader.Item("apEvent")txtWho.Text = myDataReader.Item("Who")
txt_type.Text = myDataReader.Item("_type")txtEvent_ID.Text = myDataReader.Item("Event_ID")
myDataReader.Close()
Conn.Close()
End UsingEnd Sub
 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
 Dim APEvent As String = txtapEvent.Text
Dim Who As String = txtWho.TextDim apeDate As String = txtapeDate.Text
Dim Event_ID As Integer = txtEvent_ID.TextDim _type As Integer = txt_type.Text
'add it to the DBUsing Conn As New SqlConnection("Data Source=WINSERV;Initial Catalog=EventCalendar;User ID=antonio;Password=xxxx;User Instance=False")
Conn.Open()Dim cmd As New SqlCommand("sp_editSingleEvent", Conn)
cmd.CommandType = Data.CommandType.StoredProcedurecmd.Parameters.AddWithValue("@Who", Who)
cmd.Parameters.AddWithValue("@apEvent", APEvent)cmd.Parameters.AddWithValue("@apeDate", apeDate)
cmd.Parameters.AddWithValue("@_type", _type)cmd.Parameters.AddWithValue("@Event_ID", Event_ID)
cmd.Parameters.Add(New SqlParameter("@message", SqlDbType.VarChar, 200))cmd.Parameters("@message").Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()Dim sMessage As String = Convert.ToString(cmd.Parameters("@message").Value)
Conn.Close()
lblMessage.Text = sMessage
End Using
End Sub
 
 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("MainEvent.aspx")End Sub
End Class
 ===========Stored Procedure==========USE [EventCalendar]
GO
/****** Object: StoredProcedure [dbo].[sp_EditSingleEvent] Script Date: 06/13/2007 15:15:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GOALTER PROCEDURE [dbo].[sp_EditSingleEvent]
-- Add the parameters for the stored procedure here
@apeDate smalldatetime,
@apEvent nvarchar(250),
@who nvarchar (50),
@Event_ID int,
@message nvarchar (200)OUTPUT,@_type int
AS
Begin
Set @Message = 'Hasnt added yet'
UPDATE apEvent
SET apeDate=@apeDate, apEvent=@apEvent, Who=@Who, _type=@_type
WHERE Event_ID = @Event_ID
Set @message = 'its added'
END

View 2 Replies View Related

Updating Problem

Jun 26, 2007

CREATE PROCEDURE discussions_DeletePost@post_id as intAS--prepare the variable to hold the topic_id of the post we are deletingDECLARE @topic_id int--get the topic_id from the post we are going to deleteSET @topic_id  = (SELECT topic_id from discussions_PostsWHERE post_id = @post_id)--now that we now what topic the post was in, we can delete the postDELETE FROM discussions_PostsWHERE post_id = @post_id--update topics, and just in case, if the post we deleted was the last post from the topic, give the topic a new last post_idUPDATE discussions_Topics SET topic_last_post_id = (SELECT MAX(post_id) FROM discussons_Posts WHERE topic_id = @topic_id)        WHERE topic_id = @topic_id    RETURN The problem with this is that, if I delete the last post from the topic, the topic_last_post_id feild does not update with a new post_id Any help? 

View 3 Replies View Related

Updating Problems

Aug 24, 2007

Hi
 I'm new to all of this. I have a database that holds customer
information (fictitious) and i can select that data and display it in a
set of textboxes. I also have an SQL command "UPDATE" that is designed
to update the text field that i want to edit. However the problem i'm
having is that it'll let me write the info in the textbox but as soon
as i click my update button it just flashses and goes back to what it
says before
 e.g. FIRST NAME: LEE      i enter TOM and then it reverts it back to LEE
This is my SQL UPDATE command statement:


UPDATE CustomerDetails SET [First Name] = @firstnameTextBox, [Last
Name] = @lastnameTextBox, [Address line 1] = @addressTextBox, Town =
@townTextBox, Postcode = '@postcodeTextBox', [Tel Number] = '@telephoneTextBox'  1 1
2 2 Partial Class Update
3 3 Inherits System.Web.UI.Page
4 4
5 5 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
6 6 custIDTextBox.Text = Session("Label2")
7 7
8 8 Dim updatepage As System.Data.DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), System.Data.DataView)
9 9
10 10 For Each update As Data.DataRow In updatepage.Table.Rows
11 11
12 12 firstnameTextbox.Text = update.Item("First Name").ToString
13 13 lastnameTextBox.Text = update.Item("Last Name").ToString
14 14 addressTextBox.Text = update.Item("Address Line 1").ToString
15 15 townTextBox.Text = update.Item("Town").ToString
16 16 postcodeTextBox.Text = update.Item("Postcode").ToString
17 17 telephoneTextBox.Text = update.Item("Tel Number").ToString
18 18
19 19 Next
20 20
21 21 End Sub
22 22
23 23 Protected Sub updatebutton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles updatebutton.Click
24 24
25 25 'Dim parameters firstnameTextBox, lastnameTextBox, addressTextBox, townTextBox, postcodeTextBox, telephoneTextBox
26 26 'Dim UpdateParameters As QueryStringParameter
27 27
28 28 SqlDataSource1.Update()
29 29 SqlDataSource1.UpdateParameters.Add("@CustomerDetails", System.TypeCode.String)
30 30 'SqlDataSource1.UpdateParameters.Add("@Last Name", System.TypeCode.String)
31 31 'SqlDataSource1.UpdateParameters.Add("@Address line 1", System.TypeCode.String)
32 32 'SqlDataSource1.UpdateParameters.Add("@Town", System.TypeCode.String)
33 33 'SqlDataSource1.UpdateParameters.Add("@Postcode", System.TypeCode.String)
34 34 'SqlDataSource1.UpdateParameters.Add("@Tel Number", System.TypeCode.String)
35 35
36 36 'Label2.Text = ("Update successful")
37 37 End Sub
38 38 End Class
39 39
40
41
42
 anyone?

View 2 Replies View Related

Updating By Subtracting?

Nov 5, 2007

Hi,I am currently updating a column in my database table with the value typed into a text box. But it is updating with the new value, rather than taking away the value typed in from the present value of the column. 1. How would i subtract the value typed in away from the current column value?2. I guess I need to check the column value is above 0 before updating, then rebind the control to show new values after the update has happened, incase two people are using it at once. How would this be achived? Thanks for any help!!Jon   P.S.My code is:private bool ExecuteUpdate(int quantity){  SqlConnection con = new SqlConnection();  con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True";  con.Open();  SqlCommand command = new SqlCommand();  command.Connection = con;  TextBox TextBox1 = (TextBox)FormView1.FindControl("TextBox1");  Label labname = (Label)FormView1.FindControl("Label3");  Label labid = (Label)FormView1.FindControl("Label13");  command.CommandText = "UPDATE Items SET Quantityavailable = @qty WHERE productID=@productID";  command.Parameters.Add("@qty", TextBox1.Text);  command.Parameters.Add("@productID", labid.Text); command.ExecuteNonQuery();  con.Close();  return true;}    private bool ExecuteInsert(String quantity)    {        SqlConnection con = new SqlConnection();        con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True";        con.Open();        SqlCommand command = new SqlCommand();        command.Connection = con;        TextBox TextBox1 = (TextBox)FormView1.FindControl("TextBox1");        Label labname = (Label)FormView1.FindControl("Label3");        Label labid = (Label)FormView1.FindControl("Label13");        command.CommandText = "INSERT INTO Transactions (Usersname)VALUES (@User)"+          "INSERT INTO Transactions (Itemid)VALUES (@productID)"+          "INSERT INTO Transactions (itemname)VALUES (@Itemsname)"+          "INSERT INTO Transactions (Date)VALUES (+DateTime.Now.ToString() +)"+          "INSERT INTO Transactions (Qty)VALUES (@qty)"+        command.Parameters.Add("@User", System.Web.HttpContext.Current.User.Identity.Name);        command.Parameters.Add("@Itemsname", labname.Text);        command.Parameters.Add("@productID", labid.Text);        command.Parameters.Add("@qty", TextBox1.Text);        command.ExecuteNonQuery();        con.Close();        return true;    }protected void Button2_Click(object sender, EventArgs e){  TextBox TextBox1 = FormView1.FindControl("TextBox1") as TextBox;  ExecuteUpdate(Int32.Parse(TextBox1.Text) );}protected void Button2_Command(object sender, CommandEventArgs e)    {        if (e.CommandName == "Update")        {            SqlDataSource1.Insert();        }    }}

View 7 Replies View Related

Updating A Column By The Value Of '1'

Nov 6, 2007

Hi,Its probably simple but.. How do I update a column by just '1'..for example - heres my code:    protected void Button1_Click(object sender, EventArgs e)    {        SqlConnection con = new SqlConnection();        con.ConnectionString = "HiddenConnection";        con.Open();        SqlCommand command = new SqlCommand();        command.Connection = con;        Label productIDLabel = (Label)DataList1.FindControl("productIDLabel");        command.CommandText = "UPDATE Items SET numberclickedin = numberclickedin + 1 WHERE productID=@productID";        command.Parameters.Add("@productID", productIDLabel.Text);        command.ExecuteNonQuery();        con.Close();        command.Dispose();    } As you can see in the bold text, I want to add 1 to the numberclickedin column.. and in my primative way Ive just typed +1What should I use instead?Thanks in advance,Jon 

View 1 Replies View Related

Updating Tables

Jan 19, 2008

Consider i have 2 database namely database1 and database2 . both the databases are in the same server
database1 has a following tables
1.the table "class" has following fields and many more fields. consider 50 fields but for the use of example i have given only three fields name and sample values.     class        studentname           rollno  (table name - class)    8th std      aaaaa                     100
2. the table "Fees" has the following fields  and many more fields. consider 25 field but for the use of example i have gievn only 2 fields name and sample values    rollno              fees         (table name - fees)     100                50000     101                25000
Now i have created the following tables in database2  the table "class" has the following fields only,         class          studentname              rollnothe table "fees" has the following fields only.        rollno           fess  
Question ?please let me know if there is any tool or method . to transfer values from database1 to databse2
 
 
 

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved