DataSource Controls :: Insert Row Only When A Certain Field Is Unique?

Jan 3, 2010

For example: INSERT INTO table (col1, col2, col3) VALUES ('value1','value2,'value3')But I would only like to insert the row if value3 isnt already present in col3 in some previous row. What is the best way to do that?And the insert command is run 50+ times in a loop (with different values each time for value3)

View 4 Replies


Similar Messages:

DataSource Controls :: Concatenate Field For Unique Identifier?

Feb 3, 2010

I'm using Visual Web Developer Express 2008 and SQL Management Studio Express 2005. I need to link 2 tables to either present in a Master/Detail or GridView/Form view.The goal is to allow the user to view time card information from the AS400 (read only) and then enter any corrections into a SQL table. My problem is in trying to connect the two tables.I've asked the AS400 administrator to add a unique identifier field to the table (HAPOINT), but he says he can't. I've tried to concatenate a field within Visual Web Developer's Query Builder but keep getting errors.Table 1 - exists in AS400, is non-permanent (cleared every 3 months) and can't be modifiedEmpl ID WO Date In Time In Date Out Time Out Table 2 - exists in SQL Server, newly created for this project (no data yet, so can be modified)Rev ID Empl ID Date (of revision entry) X (Revise - y/n) Revised Time In Revised Time Out I tried finding a solution through the SQL Forum, but haven't gotten a solution, so I'm posting here. There are additional details at that post:http://forums.asp.net/p/1516929/3658517.aspx#3658517Can anyone tell me how to concatenate "Empl ID /WO / Date In / Time In" from Table 1 to produce a unique identifier that I can then use in Table 2, thus providing the link between the two tables? Or, is there another way?

View 8 Replies

DataSource Controls :: Generate A Unique Ref Number And Insert Into The Database

Jul 5, 2010

I am generating a unique Ref number using this sql statement: SELECT REPLACE(STR(CAST(CAST(NEWID() AS binary(5)) AS bigint),12),0,0) as REF Subsequently, I need to insert this REF into sql database table in stored procedure. Here is what I did in my stored procedure:

USE [iBankRecords]
GO
/****** Object: StoredProcedure [dbo].[stp_addPayee] Script Date: 07/05/2010 21:57:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[stp_addPayee]
(
@CUSTID char(10),
@PAYEEACCNUM nvarchar(20),
@PAYEEACCTYPE char(10) ,
@PAYEENAME char(20),
@PAYERINITIAL char(20),
)
AS
DECLARE
@ReturnValue int
INSERT INTO PAYEE (CUSTID, PAYEEACCNUM,PAYEEACCTYPE,PAYEENAME,PAYERINITIAL, REF)
VALUES (@CUSTID,@PAYEEACCNUM,@PAYEEACCTYPE,@PAYEENAME,@PAYERINITIAL, REF)
IF @@ERROR<>0
BEGIN
PRINT 'ERROR'
SET @ReturnValue=1
RETURN @RETURNVALUE
END
ELSE
BEGIN
SET @ReturnValue=0
RETURN @RETURNVALUE
END

May I know how do I have generating a unique ref num and inserting the REF into the above statement?

View 1 Replies

DataSource Controls :: How To Insert Date And Time To Datetime Field

Apr 10, 2010

how do i insert date and time together ? what is the format for this. i tried like this but its not working.

string startDtime = TextFromDate.Text + " " + Stime;
sql_comm.Parameters.AddWithValue("@StartDate",
DateTime.Parse(startDtime));
is this the right way ? dd/mm/yyy +" "+ 00:00
or i need to make a string that contain this : dd/mm/yyy00:00
its not writing any eror it just do nothing .

View 5 Replies

DataSource Controls :: Insert A Picture Into An Image Field PictureBinary

May 29, 2010

How can we insert a picture into an image field PictureBinary?

how to do it in C# and/or T-SQL.

View 1 Replies

DataSource Controls :: Insert DBNull Value Into Varchar 1 Null Field

Aug 12, 2010

My database includes a table with sever filds which are defined as (varchar(1),null), I tried using DBNull.Value, null, ' ' but cannot get a null inserted in that field of the database,

[Code]....

View 4 Replies

DataSource Controls :: Insert Data In Xml Format In Sqldatabase Particular Field?

Jul 8, 2010

i wants to insert below all the data in a sql table called studentbackup in a single field called descfield and retrive the information

through parsing.

<?xml version="1.0" encoding="ISO-8859-1"?><studentbkup>
<studMstrDetails version = "0">
<row>
<studId>101</studId>
<studNo>Mar-10-1</studNo>
<enrolldate>20100322</enrolldate>
<title>1</title>
<initial>A</initial>
<firstName>Joseph</firstName>
<lastName>Ambrose</lastName>
<sex>1</sex>
<dob>19000101</dob>
<qualification>BE</qualification>
<college>JJ</college>
<courseId>101</courseId>

View 3 Replies

DataSource Controls :: Insert ID Field Into SQL Table Programatically From Stored Procedure?

Oct 6, 2010

I have a table in SQL where I insert data (CatCodes) using C# code but I want to insert ID code (DealerID) with it as well. Following is my Stored Procedure and C# code:

[Code]....

C#:

[Code]....

As you can see, I am insering CatCode values in Categories table using string cbspecialities.

How can I insert DealerID the same way? DealerID is automatically generated in tblDealers table when "InsertExternalInfo" asp.SqlDataSource control runs "InfoInsert" SP.

[Code]....

View 2 Replies

DataSource Controls :: Insert Into A Table Based On Another Tables Numeric Operator Field

Nov 11, 2010

I have a insert into statement thats inserting my numbers from a numeric text box on my aspx page. I am choosing the Amount Type then putting in a a number.

So i have a drop down that i select example Direct Charge then i enter 600.00 and click add it puts that in to the databse for me woot..

I then put in say Misc Credit and enter 200.00 it inserts in that into the database woot.

The look up table that has my amount types has a field called numeric opperator which is either + or - the Credit being a - and the Charge being a + then my stored procedure takes all my + numbers and adds them up and subtracts all the - numbers.

I want to change that so that it actuall be inserted into the table as a - number form the start. So I want choose Misc Credit enter 200.00 and click add then my event says o yea thats a credit insert 200.00 as -200.00

How can I do that?

[code]...

View 1 Replies

DataSource Controls :: Stored Procedure To Insert Value From A Text Field Into 2 Fields In Two Different Tables?

Mar 31, 2010

I want to insert username and password into two tables (say table1 as well as table 2) using stored procedure.

View 4 Replies

DataSource Controls :: Insert Empty Time To A Datetime Field Instand Of 1988/xx/xx?

May 14, 2010

I have trouble of saving "no time" to a datetime field in my db by using objectdatasource.I am using a formview to insert new record by an insert method in an objectdatasource.

[Code]....

View 3 Replies

DataSource Controls :: Insert A Date From Excel Sheet To Sql Server 2005 DateTime Field.

Jan 25, 2010

I want to read date field from Excel sheet and insert it into SQL Server2005.When I read date field it gives me a number say '40160' when the date feild is "08/01/2010"

How should to Read a date field from Excel Sheet Cells?

View 2 Replies

Forms Data Controls :: Insert On Details View Causes Error Cant Insert Null Into Primary Key Field?

May 22, 2010

I am using Visual studio 2010 express and I have a details view databinded to an sql database table. When I use the Insert option on the view it causes an error due to it trying to insert a null into the primary key field. If the Insert function does not create a new primary key entry how is it created?

View 9 Replies

DataSource Controls :: Columns Don't Currently Have Unique Values?

May 3, 2010

I am returning a dataset from a method and trying to set one of the columns as Primary Key.

CategoryList.Tables[0].PrimaryKey = new DataColumn[] { CategoryList.Tables[0].Columns["CategoryNodeId"] };

Interestingly it gives me this error at run-time, These columns don't currently have unique values.

Now I perfectly know why this error should error, but there are no duplicate keys in this data column. I broke the code in between and bound the dataset to gridview to check if this column contains any duplicates and this is not the case. Here is the result set underneath. Have a look at the first column 'CategoryNodeId'.

CategoryNodeId
CategoryId
Name
ParentCategoryNodeId [code]...

unable to find a work around for now.

View 3 Replies

DataSource Controls :: SQL Statement / Don't Have Any Unique Identifier?

Mar 11, 2010

I am just wondering how do I get the very last row of a join statement if I don't have any unique identifier... as in row_number field?Is there a way of creating a dummy column on my SQL statement to hold the record numbers of all records ..[1 to n] etc ???Id like to know how to do this and then I can get the MAX record number.Im using SQL server 2005 so the last() function doesn't work.

View 3 Replies

Asp Mvc Datannotation Unique Field

Jun 21, 2010

i followed [URL]. it was fine till server side but how would i be applying client side validation for unique field validation scenario on for example say username. i want to have username as unique.

View 2 Replies

DataSource Controls :: Unique Columns In A Northwind Database

Apr 6, 2010

im creating a database that needs a unique constraint on columns. does anyone know how to add this within the northwind database?

View 4 Replies

DataSource Controls :: Unique Numbers For Pulling Data?

Feb 3, 2010

I currently designed a school result portal. If the students want to view their result, they input their student school number in a text box to search out their result. But this is not secured because anybody can look up any students result if you have the number which is even written on their school uniform for identification.

I have being trying to secure this result by trying to generate or code special numbers that the students will input with their school number. The special numbers will be random numbers and may be from 10 and above, it might even contain letters. How do
I code this. I believe this is the best asp.net forum. I want the students to be inputing this special unique numbers and their student numbers so that there result will be avaliable to them.

View 2 Replies

DataSource Controls :: Return Unique Rows : T-SQL Query

Jun 11, 2010

I have an SQL database table like the following:

ID // Code // Shape

The ID is the integer identifier.

On one line the Code may be OX01 and shape Hexagon for example

Then the next line the code is still OX01 but the shape is Triangle.

What I want to do is be able to pull back data for every line that is equal to a unique Code column. in the above example OX01 Hexagon would be returned but not OX01 Triangle.

I've tried using SELECT DISTINCT but it brings back all records and doesn't filter them correctly.

I've considered having another column which could have Child/Parent data so that only the parent is returned but i'm sure there must be a better way of doing this.

View 2 Replies

DataSource Controls :: Datatable Defaultview On Unique Date?

Jun 8, 2010

I have a datatable and I want to have a view on it with unique dates. The thing is that I want the date to be unique if the year,month and day are the same, I dont care for the exact time.

I now have:

Dim dtUniqueDates As System.Data.DataTable
dtUniqueDates = dt.DefaultView.ToTable(True, "updatedate")

So in this case 12 february 2011 13:54 is different from 12 february 2011 15:54. But since year,month and day are the same I want them to be unique.

View 1 Replies

DataSource Controls :: Ignore Empty Field Because Always Join The Field And Separate By Space

Mar 3, 2010

I wanna join all the field as a new col.

but how can i ignore the empty field because i always join the field and separate by space like the following.

select (field_1+' '+field_2+' '+field_3) as new_col from TABLEA

but if the field is empty, then there is the double space

how can i ensure all the space is one space only.

View 2 Replies

DataSource Controls :: How To Get The Unique Records Randomly From Data Table

Mar 22, 2010

I have a data table with 20 records i have to get the 15 unique records randomly and have to store it in Arraylist but now problem is that how i select the 15 unique records from Data table each time .

View 9 Replies

Insert Unique Date From Textbox?

Nov 28, 2010

i need code to be able to check if (the date in a textbox) is already (used) in the database or not, if yes then give an error message!!

i am using asp.net 3.5 c#

View 3 Replies

DataSource Controls :: Pass In As An Insert Parameter For SQLds2 The Scope_identity Of The Insert Of SQLds1

Jan 12, 2010

I am trying to pass in as an insert parameter for SQLds2 the scope_identity of the insert of SQLds1.

Exception Details: System.InvalidOperationException: Error executing 'InsertCommand' in SqlDataSource 'SqlDataSource1'. Ensure the command accepts the following parameters: @Name1, @NewId

[Code]....

View 4 Replies

DataSource Controls :: Set Field As DBNull.Value If Field Is Blank?

Apr 7, 2010

I have a 20 to 30 fields on a form. Most of them are optional. However, the users can fill out what they want. If a user dosen't fill in a field when data is sent to the database it's sent as blank, instead of NULL. Is there a way I can generically say "for all textboxes if Equals("") then DBNull.Value". Without going through each and every textbox?

View 2 Replies







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