Insert Querry

Mar 16, 2007

Hello

          Can anyone give me the code to insert date from textbox to database(SQL Server 2000). The date fromat in SQL is dd-mm-yyyy.

Rathish

 

View 3 Replies


ADVERTISEMENT

Querry Help!!!

Aug 25, 2005

Is there a way I can frame the querry for the following scenario??

column1
--------
item1
item2
item3
...
..


Querry: Select datediff(month,item1,item2) and next for item2 and item3...

Thanks

View 3 Replies View Related

I Need Help With A New Querry Again

Nov 12, 2007

Hello. I know, you think I'm totally clueless, and you're right. SQL is the most confusing thing for me but I must learn it.
So, I am running a query to find out the name of the person who sold the most stoves with the least color purchased. I have ran that query and it works . My problem is that I have to add to that query another column that counts the number of stoves sold, instead of having them displayed one by one. My query is as follows:


SELECT EMPLOYEE.Name,STOVE.Color FROM INV_LINE_ITEM, STOVE, EMPLOYEE, INVOICE
WHERE INV_LINE_ITEM.FK_Stovenbr=STOVE.SerialNumber
AND INV_LINE_ITEM.FK_InvoiceNbr=INVOICE.InvoiceNbr
AND INVOICE.FK_EmpID=EMPLOYEE.EmpID
AND STOVE.Color IN (SELECT CAST(MIN(Color) AS CHAR(5)) 'Min Color' FROM STOVE)
AND EMPLOYEE.Name IN (Select CAST(MAX(Name) AS CHAR(15)) 'Employee Name' FROM EMPLOYEE)
ORDER BY EMPLOYEE.Name, STOVE.Color

Thank you

View 3 Replies View Related

Sql Sub Querry

Feb 18, 2008

I have a single table and I want to check for the duplicates. On the bases of two column.
Namley HiNum, Procode.

so if there are duplicates I want to print out those records
How I can do that in a script.

I tried the following codes but I am getting an error. how I can fix it. Or this is completly wrong?
.

Select * from Claims Where HiNum in (Select HiNum,Procode,Count(*) as NumberOfRows

From Claims

Group by HiNumber, Procode

Having Count(*) > 1)

View 2 Replies View Related

2 Updates In The Same Querry!

Oct 29, 2007

Hi! I 'd like to update the database..I 'd like to update the same field, the first update would set all to 'No' and the second update woyuld set specific records to 'Yes':
1)  "Update tblDept SET IsTop ='No'
2) "Update tblDept  SET IsTop = 'Yes'  WHERE id = 200 "
Cheers!

View 4 Replies View Related

How To Build My SQL Querry.

Nov 12, 2003

Hi.
I know this querry:

"SELECT TOP 10 * FROM MyTable ORDERBY ..."

will give the top 10 rows.

But how can I build a querry that can get the rows from 40-50 (ie).
Thanks.

View 2 Replies View Related

Need Help To Build Querry

Jan 21, 2005

I have two tables linked with the colunm name systemId and I need to get all the systems responding to the condition (t1.software & 0000000001) = 1 and if they have any contacts I would like to see them.
Here is what I have for the moment however my querry do not return the system info if no contact exist and that is wrong.

select customers.customerId,customers.systemId,customers.country
from customers,contacts
where (customers.software & 0000000001) = 1
and customers.SystemId = contacts.SystemId
order by customerid

Systems
-SystemId
-CustomerId
-Name
...

Contacts
-ContactId
-SystemId
-Name
-Tel
...

View 1 Replies View Related

Querry Question

Aug 29, 2005

I have created a small querry and for some reason my container (datalist) is not reconizing the company name This is also the first time that i have created a querry with two select statements in the sproc.... Does it make a difference if there is two select statements in a querry?? When populating a datalist?Not sure if i need to seperate the two statements some kind of way..
Is this ok to use with datalist? Erik.. ALTER PROCEDURE Get_Information_For_Datalist_Global_ @IDProduct AS INT, @IDCompany  AS INT AS SELECT  Product.ProductName,                              Product.ProductID,Product.ProductImage,                                   Product.ProductDescription, SprocsTable.*                              FROM              Product                         INNER JOIN                           SprocsTable ON Product.ProductID = SprocsTable.ProductID                        WHERE Product.ProductID = @IDProduct SELECT   Company.CompanyID, Company.CompanyName FROM COMPANY WHERE COMPANY.COMPANYID = @IDCompany

View 1 Replies View Related

Get Time Of Querry??

Dec 7, 2006

is there a way to get the time that it takes a querry to run like down to the millsecond

View 2 Replies View Related

Search Querry

Jan 26, 2008

hi.
i want to have a text box and command button. i will be entering the clients id in the text box and press the command button to search the clients record. this will be search query. i have done that previously in vb6. but dont know what query to write in vb08. Any help. thks.

View 1 Replies View Related

Displaying My Querry Horizontally

Feb 22, 2008

Is there a way to display my querry horizontally? 

View 2 Replies View Related

Enterprise Mgr Querry Error

Dec 29, 1999

There are 3 servers in our group which the Local Enterprise Manager Tool is giving us an error when we try to view local DB table data by right-clicking on the table and selecting return all rows... we get this error I thought this was a permissions error but as far as I know we haven't played with the permissions. This seems to be a common ailment here... does anyone have a fix for the EM tool.

An unexpected error happened during this operation.
[Query] - Query Designer encountered a Query error:
Unspecified error

View 2 Replies View Related

Problem With Select Into Querry

Jun 18, 2006

I have two database on same server. I want write a querry, witch qering the data from 1st database, than create a new table on the 2nd database.
But the in clause after the into clause permanently generate error.

Here is the query€™s little part:
Select €¦..
into Backup in €™Test.mdb€™ from €¦

I try wrote other ways
in €™Test€™
in €™dbo.Test€™
in dbo.Test
but none of them work

its only work, when i not want pass for the second database

How can i pass the result for the 2nd Database

View 11 Replies View Related

Running DTS From Querry Analyzer

Sep 21, 2007

Hi,How to run a DTS from query analyzer using some t-sql commands??? Is it possible?? What is the command to run a DTS from QA???and What are the possible ways of running a DTS?? from how many types we can execute a DTS like 2 of it i know from EM directly and from the help of Schedule jobs.

View 1 Replies View Related

Simple Querry Question ??

Nov 8, 2007

Dear all,


I have 2 SQL store procedure which are suppose to return similar number of data.
For an unknown reason one of the procedure is returning lasse data than the other.
in order to dig out the reason for that I need to compare the two set of data return by both procedure.

one by one is a huge woek has I have more than 1000 records.

So my question is that what is the easy way to extract data which has been forget or miss ?

For example

my procA return 500 rows
my procB return 400 rows

I would like to identify the 100 records which are in ProcA results but not in ProcB results
In other words extr^ct the difference between A and B

thnaks for your help
serge

View 5 Replies View Related

Editing In Querry Analyzer Not In EM

Nov 24, 2006

Hello,

In SQL if we want to edit a row in a table then we have two ways to do the same,

1. Execute a command to Update the records in sql through querry analyzer.

2. Go to enterprise manager and then open the table and update a new row.



But can't we do the editing in the querry analyzer is there any way to do this.

That means i select all the records from my table using the following querry.

Select * from MyTable

and then performs editing in the querry analyzer without executing any update command and without using the Enterprise manager.

Can we do this????????



Bye and TC

View 6 Replies View Related

Date Picker And Querry

Feb 3, 2008

hi.
i have created a database with a table called customer. hav a field which displays the date. how can i add a query on the date picker so that when i choose a date on the calendar i can view the customers details. in other display the record by choosing a particular date.

thx.

View 9 Replies View Related

Querry About Drivers For My Laptop.

Mar 6, 2008

i lost my laptop driver's cd,right now i am using windows XP professional.and laptop is of compaq v3000.
so from where i get my laptops driver,can you help me out .?

View 1 Replies View Related

Generating A Querry Parameters

Nov 22, 2006

Hello,

Need a bit of help here. In one table i have my production data on some wheels. Each time the wheel is touched, it gets smaller. Then in another table I have the primary data of that wheel, ie price vendor, make model and scrap diameter.

What I'd like to figure out is, In one month, what was the wheel size to start off, what is the end size to give me a total size used during that month. If i could get that, then I think I would be able to figure out what the price cost for useage of that wheel was for the month.

Any help?

Thanks Brian

View 3 Replies View Related

How To Write The Result Of A Querry To A File

Aug 15, 2000

hello!

can somebody tell me how i can redirect the result of my
select statement to a file.

thank's

View 1 Replies View Related

Querry 2 Detect Doubles In A Table

Jul 6, 1999

Hi,


I have a table which contain a field called 'company' of type 'int'.
I want to make a querry which returns all doubles ... for example:

I have: after querry the return must be:

company company:
1 1
3 3
3 3
11 3
7 2
3 1
2 2
1
4
2
5

Thank you,
Sebastian

View 1 Replies View Related

Select +replace Querry Problem..

Dec 20, 2006

Hi.every one. I have a problem when I use this querry
select replace(Title,'.','')AS Title1, ID from tbl_Sim Where Title1 LIKE '%377%'

And here is my record
Title : 0988.613.775
ID : 2

and here is the error: Invalid column name 'Title1'.
Can any one show me how to run this querry, I want to TRIM the 'Title' before it can be compared with another condition
I am a beginner. Thanks alots!

View 2 Replies View Related

Use The Reference Column Name In The Same SELECT Querry

Sep 17, 2007

Hi,
I am writing the following querry.





Code Snippet

Select dbo.fn_EnGiftId(116) AS 'EnGiftId', dbo.fn_DeGiftId(''+ EnGiftId +'') AS 'DeGiftId'
But the above querry giving me the following error When i am executing the querry:




Code Snippet

Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'EnGiftId'.
The scenario is I have created two functions 1st is for encryption of GiftId and 2nd is for Decryption of the Encrypted Giftid.
But in the same select querry i want to use the name of column which i have given to the encrypted data in the selct querry i want to use that same column name in the decryption function uin the same querry.

When i am executing the below querry it gives me the required output. So Why not above querry.




Code Snippet

Select dbo.fn_EnGiftId(116) AS 'EnGiftId', dbo.fn_DeGiftId(''+ dbo.fn_EnGiftId(116) +'') AS 'DeGiftId'
i d't want to write the encryption function again and again. Is theer any way to avoid this.?????

View 5 Replies View Related

Problem With Ative Directory Querry

Apr 2, 2008

Hi,

I linked my Active Directory catalog on my local machine as linked server. Next I querry this server, and it works pretty.

I have problem in similar situation when I linked AD as linked server on other machine and when I querry AD it yields error:

Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "
SELECT cn, mail, sn, co, distinguishedName, displayName FROM 'LDAP://DC=<domain>,DC=com'
WHERE objectClass = 'user' AND objectCategory = 'Person'
" for execution against OLE DB provider "ADSDSOObject" for linked server "(null)".



What is wrong?

View 1 Replies View Related

How To Creat A Database Via SQL Querry Analyzer To A Web Server

Nov 20, 2003

I am new to ASP.NET and met a problem about access a database on a Web Server (www.myserver.com). My meaning here that I created a .sql from my localhost to test, but when to upload to my web server on the internet, an error occured: "System.Data.SqlClient.SqlException: SQL Server does not exist or access denied".
Anyone here can help me to solve my problem. Waiting for your reply soon. Thanks

View 2 Replies View Related

Report Designer : BIDS Seems To Hang After Querry

May 16, 2007

hi,

I'm creating my first report.
I do "new project" > "report server project".
Thereafter I create my shared datasource.
Thereafter I try to add a new report.
It ask to enter my querry.

I've built up my querry previously with the querry analyser in SSMS, and there it runs quite fast.

But when i copy-paste the querry in the reporting designer, and i choose to preview it, it takes more then 20 minutes.

however, my querry it quite big, but i've written querries ten times larger in my life.
(it's about 50lines: 10 querries, union-ed together and in each one i have 4 innerjoins.... all tables are even almost empty, so it's not that indexes are missing or whatever)...

is it known that in the report designer querries are much more slower????

View 3 Replies View Related

How To Create SELECT QUERRY FOR A CHANGE ORDER FORM In ASP?

Jun 6, 2007

 Hello.
Hope you are all well and having a good day.
I've got a problem i would like you to help me out with. My
company has got a client who sells meat and my senior tech lead
has customized the cart to fit their needs and have created a
despatch table with a "simple asp form" that allows them
to scan their products in with a wi-fi scanner.

The despatch table has the following fields:
1. OrderID
2. Product
3. Quantit
4. sellbydate
5. traceabilitycode and
6. Weight
Question 1: how do i create a form in asp that allow a user to
view the order no, product and quantity
celibate,traceabilitybycode and Weight after scanning the
details into the simple form created?
Question 2: How can i create an asp form that allows users to
search for the Order that populates the orderid, Product,
quantity?
Question 3: How can i create an asp for that allows users to
search for Product with orderid,traceabilitycode and quantity?
Question 4: How can i create an asp form that allows users to
Trace: Orderid, traceabilitycode, sellbydate and Quantity?

Please find below the source code of both the:
despatchLotsRowsSimpleForm.asp that allow them to scan details
into the table and the despatchLotsExec.asp:

THE FORM:
<!#include file="../includes/settings.asp">
<!#include file="../includes/getSettingKey.asp">
<!#include file="../includes/sessionFunctions.asp">
<!#include file="../includes/databaseFunctions.asp">
<!#include file="../includes/screenMessages.asp">
<!#include file="../includes/currencyFormat.asp">

<%
on error resume next

dim mySQL, connTemp, rsTemp

' get settings
pStoreFrontDemoMode =
getSettingKey("pStoreFrontDemoMode")
pCurrencySign = getSettingKey("pCurrencySign")
pDecimalSign = getSettingKey("pDecimalSign")
pCompany = getSettingKey("pCompany")

pAuctions = getSettingKey("pAuctions")
pAllowNewCustomer = getSettingKey("pAllowNewCustomer")
pNewsLetter = getSettingKey("pNewsLetter")
pStoreNews = getSettingKey("pStoreNews")
pSuppliersList = getSettingKey("pSuppliersList")
pRssFeedServer = getSettingKey("pRssFeedServer")

%>
<b><%=getMsg(10021,"despatch")%></b>
<br>
<%=getMsg(10024,"Enter despatch ...")%>


The despatchExec.asp Page
<%
' WebShop 3.0x Shopping Cart
' Developed using ASP
' August-2002
' Email(E-Mail address blocked: See forum rules) for further information
' (URL address blocked: See forum rules)
' Details: add e-mail to newsletter list
%>

<!--#include file="../includes/settings.asp"-->
<!--#include file="../includes/getSettingKey.asp"-->
<!--#include file="../includes/databaseFunctions.asp"-->
<!--#include file="../includes/stringFunctions.asp"-->
<!--#include file="../includes/miscFunctions.asp"-->
<!--#include file="../includes/screenMessages.asp"-->
<!--#include file="../includes/sendMail.asp"-->

<%

on error resume next

dim mySQL, connTemp, rsTemp, pEmail

' get settings

pStoreFrontDemoMode = getSettingKey("pStoreFrontDemoMode")
pCurrencySign = getSettingKey("pCurrencySign")
pDecimalSign = getSettingKey("pDecimalSign")
pCompany = getSettingKey("pCompany")

pEmailSender= getSettingKey("pEmailSender")
pEmailAdmin= getSettingKey("pEmailAdmin")
pSmtpServer= getSettingKey("pSmtpServer")
pEmailComponent= getSettingKey("pEmailComponent")
pDebugEmail= getSettingKey("pDebugEmail")
pGiftRandom= getSettingKey("pGiftRandom")
pPercentageToDiscount= getSettingKey("pPercentageToDiscount")
pStoreLocation = getSettingKey("pStoreLocation")

' form
pidOrder = lcase(getUserInput(request.form("idOrder"),50))
pProduct = lcase(getUserInput(request.form("product"),50))
pQuantity = lcase(getUserInput(request.form("quantity"),50))


pPriceToDiscount = 0

' insert despatch

mySQL="INSERT INTO despatch2 (idOrder, product, quantity ) VALUES ('"
&pidOrder& "', '" &pProduct& "', '" &pQuantity&
"')"

call updateDatabase(mySQL, rstemp, "despatchExec")

pBody=getMsg(10025,"Despatch confirmed...") &VBcrlf&
getMsg(311,"To opt-out click at:") & " (URL address blocked: See
forum rules)="&pEmail

response.redirect "redit_message.asp?message="&Server.Urlencode(getMsg(10025,"Despatch confirmed"))

call closeDb()
%>

Thank you for your help in advance..
Regards,
philip

View 2 Replies View Related

(long) Querry Doesn't Fit In Query-string Window

Jun 4, 2007

hi,

i have worked three days on a query to display all my results in a beautiful report. The query is fine because when i execute it in Query Analyzer i have all results i want to see in my statistics-table in my report...

One thing: it's contains about 100 unioned statements, which results in a super-long query. Performance is OK because it are all 100 very easy statements that are union-ed together.

But, when I copy-paste it in my query-string window/textbox of the report designer, I see that there's a maximum on that textbox lenght, which results in the fact that my long query suddenly stops.

Any solutions????

View 4 Replies View Related

Insert :) I Have Different Insert Code Lines (2 Insert Codelines) Which One Best ?

Jun 4, 2008

hello friends
my one insert code lines is below :) what does int32 mean ? AND WHAT IS DIFFERENT BETWEEN ONE CODE LINES AND SECOND CODE LINES :)Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Dim cmd As New SqlCommand("Insert into table1 (UserId) VALUES (@UserId)", conn)
'you should use sproc instead
cmd.Parameters.AddWithValue("@UserId", textbox1.text)
'your value
Try
conn.Open()Dim rows As Int32 = cmd.ExecuteNonQuery()
conn.Close()Trace.Write(String.Format("You have {0} rows inserted successfully!", rows.ToString()))
Catch sex As SqlExceptionThrow sex
Finally
If conn.State <> Data.ConnectionState.Closed Then
conn.Close()
End If
End Try
MY SECOND INSERT CODE LINES IS BELOWDim SglDataSource2, yeni As New SqlDataSource()
SglDataSource2.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ToString
SglDataSource2.InsertCommandType = SqlDataSourceCommandType.Text
SglDataSource2.InsertCommand = "INSERT INTO urunlistesi2 (kategori1) VALUES (@kategori1)"
SglDataSource2.InsertParameters.Add("kategori1", kategoril1.Text)Dim rowsaffected As Integer = 0
Try
rowsaffected = SglDataSource2.Insert()Catch ex As Exception
Server.Transfer("yardim.aspx")
Finally
SglDataSource2 = Nothing
End Try
If rowsaffected <> 1 ThenServer.Transfer("yardim.aspx")
ElseServer.Transfer("urunsat.aspx")
End If
 
 
cheers

View 2 Replies View Related

Can I Insert/Update Large Text Field To Database Without Bulk Insert?

Nov 14, 2007

I have a web form with a text field that needs to take in as much as the user decides to type and insert it into an nvarchar(max) field in the database behind.  I've tried using the new .write() method in my update statement, but it cuts off the text after a while.  Is there a way to insert/update in SQL 2005 this without resorting to Bulk Insert? It bloats the transaction log and turning the logging off requires a call to sp_dboptions (or a straight-up ALTER DATABASE), which I'd like to avoid if I can.

View 6 Replies View Related

Strange Problem: SQL Insert Statement Does Not Insert All The Fields Into Table From Asp.net C# Webpage

Apr 21, 2008

An insert statement was not inserting all the data into a table. Found it very strange as the other fields in the row were inserted. I ran SQL profiler and found that sql statement had all the fields in the insert statement but some of the fields were not inserted. Below is the sql statement which is created dyanmically by a asp.net C# class. The columns which are not inserted are 'totaltax' and 'totalamount' ...while the 'shipto_name' etc...were inserted.there were not errors thrown. The sql from the code cannot be shown here as it is dynamically built referencing C# class files.It works fine on another test database which uses the same dlls. The only difference i found was the difference in date formats..@totalamount=1625.62,@totaltax=125.62are not inserted into the database.Below is the statement copied from SQL profiler.exec sp_executesql N'INSERT INTO salesorder(billto_city, billto_country, billto_line1, billto_line2, billto_name,billto_postalcode, billto_stateorprovince, billto_telephone, contactid, CreatedOn, customerid, customeridtype,DeletionStateCode, discountamount, discountpercentage, ModifiedOn, name, ordernumber,pricelevelid, salesorderId, shipto_city, shipto_country,shipto_line1, shipto_line2, shipto_name, shipto_postalcode, shipto_stateorprovince,shipto_telephone, StateCode, submitdate, totalamount,totallineitemamount, totaltax ) VALUES(@billto_city, @billto_country, @billto_line1, @billto_line2,@billto_name, @billto_postalcode, @billto_stateorprovince, @billto_telephone, @contactid, @CreatedOn, @customerid,@customeridtype, @DeletionStateCode, @discountamount,@discountpercentage, @ModifiedOn, @name, @ordernumber, @pricelevelid, @salesorderId,@shipto_city, @shipto_country, @shipto_line1, @shipto_line2,@shipto_name, @shipto_postalcode, @shipto_stateorprovince, @shipto_telephone,@StateCode, @submitdate, @totalamount, @totallineitemamount, @totaltax)',N'@billto_city nvarchar(8),@billto_country nvarchar(13),@billto_line1 nvarchar(3),@billto_line2 nvarchar(4),@billto_name nvarchar(15),@billto_postalcode nvarchar(5),@billto_stateorprovince nvarchar(8),@billto_telephone nvarchar(3),@contactid uniqueidentifier,@CreatedOn datetime,@customerid uniqueidentifier,@customeridtype int,@DeletionStateCode int,@discountamount decimal(1,0),@discountpercentage decimal(1,0),@ModifiedOn datetime,@name nvarchar(33),@ordernumber nvarchar(18),@pricelevelid uniqueidentifier,@salesorderId uniqueidentifier,@shipto_city nvarchar(8),@shipto_country nvarchar(13),@shipto_line1 nvarchar(3),@shipto_line2 nvarchar(4),@shipto_name nvarchar(15),@shipto_postalcode nvarchar(5),@shipto_stateorprovince nvarchar(8),@shipto_telephone nvarchar(3),@StateCode int,@submitdate datetime,@totalamount decimal(6,2),@totallineitemamount decimal(6,2),@totaltax decimal(5,2)',@billto_city=N'New York',@billto_country=N'United States',@billto_line1=N'454',@billto_line2=N'Road',@billto_name=N'Hillary Clinton',@billto_postalcode=N'10001',@billto_stateorprovince=N'New York',@billto_telephone=N'124',@contactid='8DAFE298-3A25-42EE-B208-0B79DE653B61',@CreatedOn=''2008-04-18 13:37:12:013'',@customerid='8DAFE298-3A25-42EE-B208-0B79DE653B61',@customeridtype=2,@DeletionStateCode=0,@discountamount=0,@discountpercentage=0,@ModifiedOn=''2008-04-18 13:37:12:013'',@name=N'E-Commerce Order (Before billing)',@ordernumber=N'BRKV-CC-OKRW5764YS',@pricelevelid='B74DB28B-AA8F-DC11-B289-000423B63B71',@salesorderId='9CD0E11A-5A6D-4584-BC3E-4292EBA6ED24',@shipto_city=N'New York',@shipto_country=N'United States',@shipto_line1=N'454',@shipto_line2=N'Road',@shipto_name=N'Hillary Clinton',@shipto_postalcode=N'10001',@shipto_stateorprovince=N'New York',@shipto_telephone=N'124',@StateCode=0,@submitdate=''2008-04-18 14:37:10:140'',@totalamount=1625.62,@totallineitemamount=1500.00,@totaltax=125.62
 
thanks

View 7 Replies View Related

Cannot INSERT Data To 3 Tables Linked With Relationship (INSERT Statement Conflicted With The FOREIGN KEY Constraint Error)

Apr 9, 2007

Hello
 I have a problem with setting relations properly when inserting data using adonet. Already have searched for a solutions, still not finding a mistake...
Here's the sql management studio diagram :

 and here goes the  code1 DataSet ds = new DataSet();
2
3 SqlDataAdapter myCommand1 = new SqlDataAdapter("select * from SurveyTemplate", myConnection);
4 SqlCommandBuilder cb = new SqlCommandBuilder(myCommand1);
5 myCommand1.FillSchema(ds, SchemaType.Source);
6 DataTable pTable = ds.Tables["Table"];
7 pTable.TableName = "SurveyTemplate";
8 myCommand1.InsertCommand = cb.GetInsertCommand();
9 myCommand1.InsertCommand.Connection = myConnection;
10
11 SqlDataAdapter myCommand2 = new SqlDataAdapter("select * from Question", myConnection);
12 cb = new SqlCommandBuilder(myCommand2);
13 myCommand2.FillSchema(ds, SchemaType.Source);
14 pTable = ds.Tables["Table"];
15 pTable.TableName = "Question";
16 myCommand2.InsertCommand = cb.GetInsertCommand();
17 myCommand2.InsertCommand.Connection = myConnection;
18
19 SqlDataAdapter myCommand3 = new SqlDataAdapter("select * from Possible_Answer", myConnection);
20 cb = new SqlCommandBuilder(myCommand3);
21 myCommand3.FillSchema(ds, SchemaType.Source);
22 pTable = ds.Tables["Table"];
23 pTable.TableName = "Possible_Answer";
24 myCommand3.InsertCommand = cb.GetInsertCommand();
25 myCommand3.InsertCommand.Connection = myConnection;
26
27 ds.Relations.Add(new DataRelation("FK_Question_SurveyTemplate", ds.Tables["SurveyTemplate"].Columns["id"], ds.Tables["Question"].Columns["surveyTemplateID"]));
28 ds.Relations.Add(new DataRelation("FK_Possible_Answer_Question", ds.Tables["Question"].Columns["id"], ds.Tables["Possible_Answer"].Columns["questionID"]));
29
30 DataRow dr = ds.Tables["SurveyTemplate"].NewRow();
31 dr["name"] = o[0];
32 dr["description"] = o[1];
33 dr["active"] = 1;
34 ds.Tables["SurveyTemplate"].Rows.Add(dr);
35
36 DataRow dr1 = ds.Tables["Question"].NewRow();
37 dr1["questionIndex"] = 1;
38 dr1["questionContent"] = "q1";
39 dr1.SetParentRow(dr);
40 ds.Tables["Question"].Rows.Add(dr1);
41
42 DataRow dr2 = ds.Tables["Possible_Answer"].NewRow();
43 dr2["answerIndex"] = 1;
44 dr2["answerContent"] = "a11";
45 dr2.SetParentRow(dr1);
46 ds.Tables["Possible_Answer"].Rows.Add(dr2);
47
48 dr1 = ds.Tables["Question"].NewRow();
49 dr1["questionIndex"] = 2;
50 dr1["questionContent"] = "q2";
51 dr1.SetParentRow(dr);
52 ds.Tables["Question"].Rows.Add(dr1);
53
54 dr2 = ds.Tables["Possible_Answer"].NewRow();
55 dr2["answerIndex"] = 1;
56 dr2["answerContent"] = "a21";
57 dr2.SetParentRow(dr1);
58 ds.Tables["Possible_Answer"].Rows.Add(dr2);
59
60 dr2 = ds.Tables["Possible_Answer"].NewRow();
61 dr2["answerIndex"] = 2;
62 dr2["answerContent"] = "a22";
63 dr2.SetParentRow(dr1);
64 ds.Tables["Possible_Answer"].Rows.Add(dr2);
65
66 myCommand1.Update(ds,"SurveyTemplate");
67 myCommand2.Update(ds, "Question");
68 myCommand3.Update(ds, "Possible_Answer");
69 ds.AcceptChanges();
70

and that causes (at line 67):"The INSERT statement conflicted with the FOREIGN KEY constraint
"FK_Question_SurveyTemplate". The conflict occurred in database
"ankietyzacja", table "dbo.SurveyTemplate", column
'id'.
The statement has been terminated.
at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
at AnkietyzacjaWebService.Service1.createSurveyTemplate(Object[] o) in J:\PL\PAI\AnkietyzacjaWebService\AnkietyzacjaWebServicece\Service1.asmx.cs:line 397"


Could You please tell me what am I missing here ?
Thanks a lot.
 

View 5 Replies View Related

OPENROWSET (INSERT) Insert Error: Column Name Or Number Of Supplied Values Does Not Match Table Definition.

Mar 24, 2008

Is there a way to avoid entering column names in the excel template for me to create an excel file froma  dynamic excel using openrowset.
I have teh following code but it works fien when column names are given ahead of time.
If I remove the column names from the template and just to Select * from the table and Select * from sheet1 then it tells me that column names donot match.
 Server: Msg 213, Level 16, State 5, Line 1Insert Error: Column name or number of supplied values does not match table definition.
here is my code...
SET @sql1='select * from table1'SET @sql2='select * from table2'  
IF @File_Name = ''      Select @fn = 'C:Test1.xls'     ELSE      Select @fn = 'C:' + @File_Name + '.xls'        -- FileCopy command string formation     SELECT @Cmd = 'Copy C:TestTemplate1.xls ' + @fn     
-- FielCopy command execution through Shell Command     EXEC MASTER..XP_CMDSHELL @cmd, NO_OUTPUT        -- Mentioning the OLEDB Rpovider and excel destination filename     set @provider = 'Microsoft.Jet.OLEDB.4.0'     set @ExcelString = 'Excel 8.0;HDR=yes;Database=' + @fn   
exec('insert into OPENrowset(''' + @provider + ''',''' + @ExcelString + ''',''SELECT *     FROM [Sheet1$]'')      '+ @sql1 + '')         exec('insert into OPENrowset(''' + @provider + ''',''' + @ExcelString + ''',''SELECT *     FROM [Sheet2$]'')      '+ @sql2 + ' ')   
 
 

View 4 Replies View Related







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