Updating Database From Dataset (Insert INTO)

Mar 2, 2007



Hello there

I have a code to update an access database from one of my dataset tables, but i want to insert columns manually

currently i am using this code to update my db

Dim cb As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(dtadpt)

AccessConn.Open()

dtadpt.Update(DataSet, "recordsforupdate")

AccessConn.Close()

this code automatically inserts all the columns of dataset table to the access database table.

what i want is to inset the values for eg. in col4 of my dataset table into col5 of my access table, for that i want to manually use "inset into" statement to update the db table, but i am having problem with the syntax for using dataset..can anyone help please

thanks and bext regards

Saad

View 1 Replies


ADVERTISEMENT

Updating/Insert With Dataset Or Queries

Jun 1, 2007

Hi,Ive got a class in my code which contains data from several tables. A user profile has a single record in a user_profile tables, for each of these records there is several records in a another table, which itself has several records in a tags table.So far the save method on the class saves the record to the user profile table, then loops through the next two tables info to insert each record. I want to decrease the number of trips to the database and am wondering if anyone can advise on the best way to do this.I am considering using a dataset to retrieve and store the records, instead of a datareader Im using currently. Then when Im done altering the data in the dataset (all three tables) I can commit all the changes in one database transaction?? I have been avoiding datasets due to the fact datareaders are apparently faster.My other option is to try make three calls to the database, one per table, updating my stored procedures to accept arrays of data using XML?? Can anyone tell me what is the best option for me?Thanks,C 

View 5 Replies View Related

Updating The Database From The Dataset

Jul 22, 2007

I am having the oddest problem. I can update the data in the dataset, but when I use the update command, or try to do a update manually it will not save the values back to the database.



public void insrtnewtime()

{

int begintime = 00;

int endtime = 23;

int countr;

int _minz;

do

{

begintime = begintime + 1;

string string_begintime_representation = begintime.ToString("00");



//now I have a valid string representations

int _year = 2007;

int _month = 1;

int _day = 1;

int _hour = int.Parse(string_begintime_representation);

_minz = 00;

//need to account for 60 minutes



do

{

//now I need to get a real nice representation to be shown for the visual display

DateTime temptime = new DateTime(_year, _month, _day, _hour, _minz, 0);

//Now I need to strip out just the time, and send it to my stored proc

string stringnewtime_rep_visual = temptime.ToString("t");

string stringnewtime_rep_visual24 = temptime.ToString("HH:mm");



this.tbl_strt_tmesTableAdapter.insrt_strt_times(stringnewtime_rep_visual24, stringnewtime_rep_visual);



_minz += 5;

}

while (_minz < 60);

countr = begintime;

} while (countr < endtime);

this.tbl_strt_tmesTableAdapter.Fill(this.lesson_plannerDataSet.tbl_strt_tmes);

try

{

tbl_strt_tmesTableAdapter.Update(lesson_plannerDataSet.tbl_strt_tmes);//this should save the values

}

catch (Exception e)

{

MessageBox.Show(e.Message);

}









}





the table adapter update, should send the values to the database, but for some reason, it is not. i can see the existing values from the database, along with my new values that i added in my loop, but those values are not being sent to the database when I invoke the update command on the data adapter.

Any help will be greatly appreciated. I am making this program for my wife who is a school teacher.

View 1 Replies View Related

Problem With Update When Updating All Rows Of A Table Through Dataset And Saving Back To Database

Feb 24, 2006

Hi,
I have an application where I'm filling a dataset with values from a table. This table has no primary key. Then I iterate through each row of the dataset and I compute the value of one of the columns and then update that value in the dataset row. The problem I'm having is that when the database gets updated by the SqlDataAdapter.Update() method, the same value shows up under that column for all rows. I think my Update Command is not correct since I'm not specifying a where clause and hence it is using just the value lastly computed in the dataset to update the entire database. But I do not know how to specify  a where clause for an update statement when I'm actually updating every row in the dataset. Basically I do not have an update parameter since all rows are meant to be updated. Any suggestions?
SqlCommand snUpdate = conn.CreateCommand();
snUpdate.CommandType = CommandType.Text;
snUpdate.CommandText = "Update TestTable set shipdate = @shipdate";
snUpdate.Parameters.Add("@shipdate", SqlDbType.Char, 10, "shipdate");
string jdate ="";
for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++)
{
jdate = ds.Tables[0].Rows[i]["shipdate"].ToString();
ds.Tables[0].Rows[i]["shipdate"] = convertToNormalDate(jdate);
}
da.Update(ds, "Table1");
conn.Close();
 
-Thanks

View 4 Replies View Related

Insert Multiple Rows From Dataset Into SQL Database

Aug 16, 2006

Hi,
is there anyway to insert all the rows from a dataset to SQL Server table in a single stretch..

Thanks
Anz

View 1 Replies View Related

Insert Unicode Data Into The Database With Typed DataSet

Dec 11, 2006

Hi all,I am using a Strongly Typed DataSet (ASP.NET 2.0) to insert new data into a SQL Server 2000 database, types of some fields in db are nvarchar. All thing work fine except I can not insert unicode data(Vietnamese language) into db.I can't find where to put prefix N. Please help me!!!   

View 1 Replies View Related

Updating Column In A Dataset Not Working

Aug 8, 2006

Hi all,
I'm trying to update various rows in my DB with a new value once an action occurs.  I am using the following code which does not throw any exceptions, but also does not change the values.  Can someone steer me in the right direction?
public static void ChangeRefCode()
{
SqlConnection dbConn = new SqlConnection(ConnectDB.getConnectString());
SqlDataAdapter dataAdapt = new SqlDataAdapter("Select * from Posting",dbConn);

DataSet ds = new DataSet();

SqlCommandBuilder sqBuilder = new SqlCommandBuilder(dataAdapt);
dataAdapt.Fill(ds, "Posting");
foreach (DataRow dr in ds.Tables["Posting"].Rows)
{
dr["ref_code"] = DateTime.Today.Ticks + "-" + dr["poster"].ToString();
}
try
{
dataAdapt.Update(ds, "Posting");
}
catch (Exception ex)
{
ex.ToString();
}
finally
{
dbConn.Close();
}
}

View 3 Replies View Related

Add Rows To A DataSet Without Updating The MS SQL Server?

Jan 9, 2006

I am using ASP.NET 2.0 WebForms and I was trying to use a DataSet to add rows programatically without adding the actual records to the MS SQL Server Databases. Is this possible or should I be doing this another way?
DataSet myDS = new DataSet();DataTable myTable = new DataTable("table1");myTable.Columns.Add("col1", typeof(string));myDS.Tables.Add(myTable);myTable.Rows.Add("MyValue");
Thanks.

View 1 Replies View Related

Updating The Image Field In SQL Server Via DataSet

Aug 22, 2006

Hello,I am trying to update the Image type field named as BlobData in sqlServer 2000. I capture the record in a data set to have the schema and try to update the BlobData field of type Image by assigning it a value of buffer as below. but my assignment seems to be wrong and generates an error saying Object reference not set.
Code=========================
Dim fileBuffer(contentLength) As Byte
 
Dim attachmentFile As HttpPostedFile = Me.fileUpload_fu.PostedFile
 
attachmentFile.InputStream.Read(fileBuffer, 0, contentLength)
 
Dim cn As SqlClient.SqlConnection
 
Try
      Dim sSQL As String
      Dim cmd As SqlClient.SqlCommand
      Dim da As SqlClient.SqlDataAdapter
      Dim ds As System.Data.DataSet = New DataSet
 
      cn = New SqlClient.SqlConnection(myconnectionString)
 
cn.Open()
 
sSQL = "SELECT * FROM Attachment WHERE ID = " & attachmentRecordID
                           
cmd = New SqlClient.SqlCommand(sSQL, cn)
 
da = New SqlClient.SqlDataAdapter(cmd)
 
da.Fill(ds)
If (ds.Tables(0).Rows.Count = 1) Then
 
      ' ======================================
' ERROR GENERATED HERE
' ======================================
 
ds.Tables("Attachment").Rows(0).Item("BlobData") = fileBuffer
' ====================================== 
 
da.Update(ds, "Attachment")
 
Return True
Else
Return False
End If
 
Catch ex As Exception
Me.error_lbl.Text = ex.Message
            Return False
Finally
cn.Close()
End Try
==========================
Can anyone please help this one out.
Cheers.Imran.

View 2 Replies View Related

Updating A Permanent Table From A Dataset Within The Data Flow

Feb 14, 2007

I have a dataset that was created via a source + lookups + derived columns.

I wish to take this dataset and treat is as a table within a sql statement so that I can update a permanent table with the a specific value within the temp dataset.

In sql this is what I am trying to do:

SELECT COUNT(*) AS Count_of_Employees, DEPT
FROM Employees
GROUP BY DEPT

UPDATE Departments
SET Number_of_Employees = Count_of_Employees
WHERE Dept = dept.

View 1 Replies View Related

DataSet And Insert Method

Apr 6, 2006

hi,

i created a query to insert a row in DataSet in Visual Studio 2005. i gave the method name to the query i created. as i understood it returns '1' if successful or '0' if not.

is it possible to get the ID or the row instead?

View 7 Replies View Related

Updating Records Instead Of Insert

Jul 29, 2006

Dear All,

I want to use SSIS in order to synchronize data. The OLEDB and ADO.NET Destination Adapter just inserts the rows read from the source. Since I have PK Constraint on destination, the tranform fails. How can I ask to update the records in destination DB?

Regards,
Sassan

View 4 Replies View Related

DateTime.Now, An Allowed Null Field, And My Insert Function From My Dataset

Jun 6, 2008

I have a table adapter for one of my SQL2005 tables, and in two different fields I accept a date time. Now 99% of the times, new rows to this table will be filled out using DateTIme.Now(), as a Time Stamp is what I'm going for.
 
Here is the line of code in question...cops_current_data_adapter.Insert(ProductOrder, Convert.ToInt16(Session["StationId"].ToString()),
PartNumber, DateTime.Now, DateTime.Now, Convert.ToInt16(qty), 0);
 The second DateTime.Now is the one that can be null, and it's throwing a formatting error everytime I try and drop it in there. It's a FormatException, and there's not much more to the example except unhelpful tips like be careful when conveting a string to a dateTime, which I'm not doing. Needless to say for the code to compile, and then throw a Format error at runtime is a bit frustraiting.
 Any suggestions would be most appreciated

View 1 Replies View Related

SQL Server 2014 :: Insert Dataset Into Two Tables And Grabbing Identity From One For Other

Jan 2, 2015

Ok I think I will need to use a temp table for this and there is no code to share as of yet. Here is the intent.

I need to insert data into two tables (a header and detail table) the Header Table will give me lets say an order number and this order number needs to be placed on the corresponding detail lines in the detail table.

Now if I were inserting a single invoice with one or more detail lines EASY, just set @@Identity to a variable and do a second insert statement.

What is happening is I will be importing a ton of Invoice headers and inserting those into the header table. The details are already in the database across various tables and and I will do that insert based on a select with some joins. As stated I need to get the invoice number from IDENTITY of the header table for each DETAIL insert.

I am assuming the only way to do this is with a loop... Insert one header, get identity; Insert the detail table and include the IDENTITY variable, and repeat.

View 9 Replies View Related

Updating A Column With Scope_Identity After An Insert Sometimes Does Not Work

Jan 21, 2008



Hello,

I have the following stored procedure that inserts records and updates the new record. The parameter @rpt_id has a value of -1 when entering the procedure. It needs to be updated with the new record if (identity) once the record is inserted, bu sometimes the update does not happen. The new records ends up with -1 in the rpt_id column.

I have included the stored procedure. I will appreciate any ideas?


ALTER PROCEDURE [dbo].[thhill_InsertReport]

(

@RPT_ID int,

@REPORT_DATE datetime,

@COMMIT_DATE datetime,

@JOB_NUMBER nvarchar(50),

@TECH_NAME nvarchar(75),

@CLIENT_NAME nvarchar(255),

@CLIENT_CONTACT nvarchar(75),

@CITY nvarchar(75),

@STATE nvarchar(75),

@COUNTRY nvarchar(75),

@SUPPLIER nvarchar(75),

@WORK_ORDER nvarchar(75),

@RIG_NAME nvarchar(75),

@WELL_NAME nvarchar(75),

@OCSG_NUMBER nvarchar(75),

@AFE_NUMBER nvarchar(75),

@MGMT varchar(6000),

@Complete varchar(3),

@newReportId int output,

@changeCommitDate bit = 1

)

AS

SET NOCOUNT ON;

if @changeCommitDate = 1

set @COMMIT_DATE = getdate()

INSERT INTO [reports] ([RPT_ID], [REPORT_DATE], [COMMIT_DATE], [JOB_NUMBER], [TECH_NAME], [CLIENT_NAME], [CLIENT_CONTACT], [CITY], [STATE], [COUNTRY], [SUPPLIER], [WORK_ORDER], [RIG_NAME], [WELL_NAME], [OCSG_NUMBER], [AFE_NUMBER], [MGMT], [isReportComplete])

VALUES (@RPT_ID, @REPORT_DATE, @COMMIT_DATE, @JOB_NUMBER, @TECH_NAME, @CLIENT_NAME, @CLIENT_CONTACT, @CITY, @STATE, @COUNTRY, @SUPPLIER, @WORK_ORDER, @RIG_NAME, @WELL_NAME, @OCSG_NUMBER, @AFE_NUMBER, @MGMT, @Complete );

declare @reference int, @tmpReportId int

set @tmpReportId = SCOPE_IDENTITY()

set @reference = @tmpReportId * -1


SET NOCOUNT Off;


Update [reports] set [RPT_ID] = @reference where id = @tmpReportId

select @newReportId = RPT_ID

FROM REPORTS

WHERE (ID = @tmpReportId)

View 3 Replies View Related

Queued Updating - Missing Insert Proc

Oct 17, 2007

Hi

I'm running transactional repl with updateable subscribtions - queued updating. Running SQL 2005 sp2, win 2003 sp1

I have 18 odd subscribers at the moment, my publisher and disttribution is on the same machine with push subscriptions.

The questions I have

nr 1.
While trying to initialize new subscribers I get loads of deadlocks even after I stop dist cleanup agent. This *I think* cause some other unexpected problems.

nr2.
The queue reader would fail saing it cannot find the "insert" proc on the publisher, although it exists.
I have changed anything on the publication so I'm not sure how this happens or why.

nr3.
I replicate a varbinary(max) column and on the odd occasion get the "Length of LOB data" errors which I then set with sp_configure. The catch here is that the length never exceeds a "len()" of 4000, thus the reported LOB and my calculation doesn't tie up.

Help is appreciated.

Thanks




View 3 Replies View Related

Updating A Production Database With Back Up Of Development Database

May 11, 2007

Can someone provide a step by step tutorial for this? I'd like to safely update a database that is used for a website without much or any downtime.

View 1 Replies View Related

Updating Online SQL 2005 Database From Local Database

Jan 30, 2007

I have my first small SQl Server 2005 database developed on my localserver and I have also its equivalent as an online database.I wish to update the local database (using and asp.net interface) andthen to upload the data (at least the amended data, but given thesmall size all data should be no trouble) to the online database.I think replication is the straight answer but I have no experience ofthis and I am wondering what else I might use which might be lesscomplicated. One solution is DTS (using SQL 2000 terms) but i am notsure if I can set this up (1) to overwrite existing tables and (2) notto seemingly remove identity attributes from fields set as identities.I know there are other possibilities but I would be glad of advice asto the likely best method for a small database updated perhaps onceweekly or at less frequent intervals,Best wishes, John Morgan

View 3 Replies View Related

Updating A Table On My Hosted Database From A Local Database

Aug 1, 2007

Hi,

How do I insert data that I have collected in a local database onto a table on my online ie hosted database which is on a different server?

At the moment I am just uploading all the data to the hosted DB but this is wasting bandwith as only a small percentage of data is actually selected and used.

I thought that if i used a local DB and then update the table on my hosted DB this would be much more efficient, but I am not sure how to write the SQL code to do this!

Do I do some kind of

INSERT INTO sample_table

SELECT xxx

FROM origanal_table



Or is it more complicated than this?

Thanks

View 6 Replies View Related

Updating Sql Database From Linked Access Database

Jul 1, 2004

I got thrown into a new project that is going to require me to update an SQL server database tables from an Access table on the backend of an Oracle database on another server. At the end of each day the Access dabase will be updated from the Oracle database.

What I need to do, is when the Access database is updated I need to have the table in the SQL database automaticaly updated. When a new record is added to the Access table I need the new record added to the SQL table. When a record is deleted in the Access table I need to keep that record in the SQL table and set a field to a value (such as 0). And when a record is updated in Access, have it updated in SQL.

Needless to say this is a bit out of my area and not sure how to accomplish this.

Any help is greatly appreciated.

View 2 Replies View Related

Updating Sql 2000 Database From Sql 2005 Database

Jul 27, 2006

i have sql 2005 installed on my personal machine, but our server has sql 2000 on it. the structure of my database was made on the server, but i'm not sure how to update the server copy from my local copy. when i try to export my data from my local machine to the server (or import from my local machine to the server), i get pre-execute errors.

roughly every other week, i'll need to be able to update the server version from my local version, so i'm trying to find the most efficient method. what is the best way to update a 2000 database from a 2005 database? it doesn't matter if i append or overwrite, but i do use identity fields. the error i get when trying to use the import/export wizard is:



- Pre-execute (Error)



Messages

Error 0xc0202009: Data Flow Task: An OLE DB error has occurred. Error code: 0x80040E21.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E21 Description: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".
(SQL Server Import and Export Wizard)


Error 0xc0202025: Data Flow Task: Cannot create an OLE DB accessor. Verify that the column metadata is valid.
(SQL Server Import and Export Wizard)


Error 0xc004701a: Data Flow Task: component "Destination 3 - ReleaseNotes" (202) failed the pre-execute phase and returned error code 0xC0202025.
(SQL Server Import and Export Wizard)

View 4 Replies View Related

SQL Server 2008 :: Populate One Dataset In SSRS Based On Results From Another Dataset Within Same Project?

May 26, 2015

I have a report with multiple datasets, the first of which pulls in data based on user entered parameters (sales date range and property use codes). Dataset1 pulls property id's and other sales data from a table (2014_COST) based on the user's parameters. I have set up another table (AUDITS) that I would like to use in dataset6. This table has 3 columns (Property ID's, Sales Price and Sales Date). I would like for dataset6 to pull the Property ID's that are NOT contained in the results from dataset1. In other words, I'd like the results of dataset6 to show me the property id's that are contained in the AUDITS table but which are not being pulled into dataset1. Both tables are in the same database.

View 0 Replies View Related

Integration Services :: Perform Lookup On Large Dataset Based On A Small Dataset

Oct 1, 2015

I have a small number of rows in a dataset, Table 1.  There is a CLOB on a large dataset, Table 2.  They join on a PK.  I would like to retrieve this CLOB and add it to the data flow for Table1.  In short I want to emulate the following:

Table 1:  Small table without CLOB, 10 rows. 
Table 2: Large table with CLOB, 10,000,000 rows

select CLOB
from table2
where pk = (select pk from table1)

I want this to return the CLOBs for the small number of rows in Table 1.  The PK is indexed obviously so it should be a fast look up.

Table 1 and Table 2 live on different Oracle databases.  How do I perform this operation efficiently in SSIS?  It seems the Lookup and Merge Join wont do this.

View 2 Replies View Related

Reporting Services :: Populate One Dataset In SSRS Based On Results From Another Dataset Within Same Project?

May 27, 2015

I have a report with multiple datasets, the first of which pulls in data based on user entered parameters (sales date range and property use codes). Dataset1 pulls property id's and other sales data from a table (2014_COST) based on the user's parameters.

I have set up another table (AUDITS) that I would like to use in dataset6. This table has 3 columns (Property ID's, Sales Price and Sales Date). I would like for dataset6 to pull the Property ID's that are NOT contained in the results from dataset1. In other words, I'd like the results of dataset6 to show me the property id's that are contained in the AUDITS table but which are not being pulled into dataset1. Both tables are in the same database.

View 3 Replies View Related

How Can I Use SQL Reporting Services To Get A Dynamic Dataset From Another Web Service As My Reports Dataset?

May 21, 2007

I found out the data I need for my SQL Report is already defined in a dynamic dataset on another web service. Is there a way to use web services to call another web service to get the dataset I need to generate a report? Examples would help if you have any, thanks for looking

View 2 Replies View Related

Getting Data From Dataset Back Into Database

Sep 7, 2006

I'm new at this so I apologize in advance for my ignorance.

I'm creating a website that collects dates in a calendar control (from Peter Blum). When the page containing the control loads it populates the calendar with dates from the database (that have previously been selected by the user). The user then can delete existing dates and/or add new dates.

I create a dataset when the page loads and use it to populate the calendar. When the user finishes adding and deleting dates in the calendar control I delete the original dates from the dataset and then write the new dates to the dataset. I then give execute the data adapter update command to load the contents of the dataset back into the database. This command involves using parameterized queries. For example the Insert command is:

Dim cmdInsert As SqlCommand = New SqlCommand("INSERT INTO Requests VALUES(@fkPlayerIDNumber, @RequestDate, @PostDate, @fkGroupID)", conn)

cmdInsert.Parameters.Add(New SqlParameter("@fkPlayerIDNumber", SqlDbType.Int))

cmdInsert.Parameters.Add(New SqlParameter("@RequestDate", SqlDbType.DateTime))

cmdInsert.Parameters.Add(New SqlParameter("@PostDate", SqlDbType.DateTime))

cmdInsert.Parameters.Add(New SqlParameter("@fkGroupID", SqlDbType.Int))

da.InsertCommand = cmdInsert

The update command is:

da.Update(ds, "Requests")

When I run the program I get the following error:

Parameterized Query '(@fkPlayerIDNumber int,@RequestDate datetime,@PostDate datetime,' expects parameter @fkPlayerIDNumber, which was not supplied.

I've used debug print to establish that the table in the dataset contains what it should.

I would be more than grateful for any suggestions.

View 3 Replies View Related

Listing Datasets In Report (dataset Name, Dataset's Commands)

Oct 12, 2007



Is there any way to display this information in the report?

Thanks

View 3 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

Updating A Sql Database From Asp.net

May 25, 2005

Im sorry for how simple this question is im.. brand new at this.I am trying to write a program that will take information entered in 4 txt fields on a webform and populate a sql database with them with a submit button..   Eventually its going to be a updateable phone list for my department but for now im just trying to get the submit button to work.  More then anything i just need a good resourse to read up on it. Thankyou Adam

View 2 Replies View Related

Updating The Database

Nov 15, 2003

At present I am working on a school project. the project was installed few months back. database is MSsql server.
Because of some new things i had to change few tables, add few columns and add few tables also. Now My problem is that the school is already having the data which they don't want to be disturbed . So I want My structure and their data.

:confused: :(
Please Help Me.

View 4 Replies View Related

Updating The Database

Jul 20, 2005

I'm having a difficult time calling UPDATE when my 'WHERE" clause calls ID,which is numeric and the primary key. I found that I can do a SELECT justfine with "WHERE ID".. Is there something special about UPDATE that i'm notgetting? I've searched the internet but it appears that what I'm doingshould work.Any help would be greatly appreciated.if (modcustomer == "relate"){var modid1 = Request.Form ("modid1");var modid2 = Request.Form ("modid2");var relationship = Request.Form ("relationship");var comments = Request.Form("comments");SqlString = "UPDATE Customer SET Relationship = ' " + relationship + " 'WHERE ID = " + modid1;connection.Execute (SqlString);}thanks,Debbie EhrlichReliable Software - Developers of Code Co-op®, Server-less version controlfor distributed teams www.relisoft.com

View 3 Replies View Related

Updating Database

May 17, 2006

Can someone please tell me what I am missing... I am trying to update a record with information a user types into a textbox. I am not getting any errors even when in DEBUG mode. But yet the Data is not getting updated.

Any Help would be very much appreciated.

T

CODE:

Protected Sub bUpdateSlsNum_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bUpdateSlsNum.Click

Dim myCommand As SqlCommand

Dim myConnection As SqlConnection

myConnection = New SqlConnection("Server=.SQLEXPRESS;AttachDbFilename=|DataDirectory|CustomerInfo.mdf;Integrated Security=True;User Instance=True")

Dim UpdateCmd As String = "UPDATE CustomerSalesNum SET WorkSheetID=@WorkSheetID, Price=@Price, Freight=@Freight, Setup=@Setup, " _

& "Injection=@Injection, Wheels=@Wheels, Security=@Security, SubTotal=@SubTotal, DocFee=@DocFee, TradeInAllow=@TradeInAllow, TaxAmount=@TaxAmount, SalesTax=@SalesTax, " _

& "TradeLienBal=@TradeLienBal, Other=@Other, PAQuote=@PAQuote, TitleFee=@TitleFee, DownPay=@DownPay, Total=@Total WHERE [WorkSheetID]= '" & "@" & lblRWorkSheetID.Text & "'"

myCommand = New SqlCommand(UpdateCmd, myConnection)

myCommand.Parameters.Add(New SqlParameter("@WorkSheetID", Data.SqlDbType.NVarChar))

myCommand.Parameters("@WorkSheetID").Value = lblRWorkSheetID.Text

myCommand.Parameters.Add(New SqlParameter("@Price", Data.SqlDbType.NVarChar))

myCommand.Parameters("@Price").Value = tbUPPRice.Text

myCommand.Parameters.Add(New SqlParameter("@Freight", Data.SqlDbType.NVarChar))

myCommand.Parameters("@Freight").Value = tbUPFreight.Text

myCommand.Parameters.Add(New SqlParameter("@Setup", Data.SqlDbType.NVarChar))

myCommand.Parameters("@Setup").Value = tbUPSetup.Text

myCommand.Parameters.Add(New SqlParameter("@Injection", Data.SqlDbType.NVarChar))

myCommand.Parameters("@Injection").Value = tbUPInjection.Text

myCommand.Parameters.Add(New SqlParameter("@Wheels", Data.SqlDbType.NVarChar))

myCommand.Parameters("@Wheels").Value = tbUPWheels.Text

myCommand.Parameters.Add(New SqlParameter("@Security", Data.SqlDbType.NVarChar))

myCommand.Parameters("@Security").Value = tbUPFactorySec.Text

myCommand.Parameters.Add(New SqlParameter("@SubTotal", Data.SqlDbType.NVarChar))

myCommand.Parameters("@SubTotal").Value = tbUPSUBT.Text

myCommand.Parameters.Add(New SqlParameter("@DocFee", Data.SqlDbType.NVarChar))

myCommand.Parameters("@DocFee").Value = tbUPDOCFee.Text

myCommand.Parameters.Add(New SqlParameter("@TradeInAllow", Data.SqlDbType.NVarChar))

myCommand.Parameters("@TradeInAllow").Value = tbUPTIA.Text

myCommand.Parameters.Add(New SqlParameter("@TaxAmount", Data.SqlDbType.NVarChar))

myCommand.Parameters("@TaxAmount").Value = tbUPTAX.Text

myCommand.Parameters.Add(New SqlParameter("@SalesTax", Data.SqlDbType.NVarChar))

myCommand.Parameters("@SalesTax").Value = tbUPSALETAX.Text

myCommand.Parameters.Add(New SqlParameter("@TradeLienBal", Data.SqlDbType.NVarChar))

myCommand.Parameters("@TradeLienBal").Value = tbUPTILB.Text

myCommand.Parameters.Add(New SqlParameter("@Other", Data.SqlDbType.NVarChar))

myCommand.Parameters("@Other").Value = tbUPOther.Text

myCommand.Parameters.Add(New SqlParameter("@PAQuote", Data.SqlDbType.NVarChar))

myCommand.Parameters("@PAQuote").Value = tbUPPAQuote.Text

myCommand.Parameters.Add(New SqlParameter("@TitleFee", Data.SqlDbType.NVarChar))

myCommand.Parameters("@TitleFee").Value = tbUPTitle.Text

myCommand.Parameters.Add(New SqlParameter("@DownPay", Data.SqlDbType.NVarChar))

myCommand.Parameters("@DownPay").Value = tbUPDownPay.Text

myCommand.Parameters.Add(New SqlParameter("@Total", Data.SqlDbType.NVarChar))

myCommand.Parameters("@Total").Value = LBLUTOTAL.Text

myCommand.Connection.Open()

Try

myCommand.ExecuteNonQuery()

ShowMessageBox(Me, "ATTENTION: Customer Data has been Updated.")

bUpdateSlsNum.Enabled = False

Catch ex As SqlException

If ex.Number = 2627 Then

ShowMessageBox(Me, "ERROR: A record already exists with " _

& "the same primary key")

Else

ShowMessageBox(Me, "ERROR: Could not add record")

End If

End Try

myCommand.Connection.Close()

MVMain.ActiveViewIndex = -1

End Sub

View 6 Replies View Related

Updating SQL Database

Feb 9, 2008

Hi,

I have designed a Contacts application, where I store all the Contacts in a SQL Database.

Now, I am deploying this application using Visual Studio 2005 Setup and Deployment project.


I might need the update the database with additional Columns etc at a later stage.

How, can I update the SQL Database after it has been deployed on a client computer?


Please assist

Thanks

View 8 Replies View Related







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