Showing posts with label fields. Show all posts
Showing posts with label fields. Show all posts

Friday, March 30, 2012

Problems with Table Adapters

1) I have added new fields to the database, now seeems I need to remove method from table adapter and add it again. Is there any simple way to have table adapter refreshed after adding a field to the stored procedure?

2) Also I have noticed that when I try to edit existing method (configure option), it tells me that method name can not be the same for fill and get. any idea? It is the same now...

3) Also How do I remove the default method? Delete option is greyed out...

Thanks a lot

hi,


We cannot delete the default method.this method is user to fill and select(Default select command)

Right Click the default method and click on Configure..Now If u are using a stored Procedure then u can see the stored procedure name on the select dropdown.

Click the previous button and select the radio button new stored procedure or select the sql statement (if u are selecting the sql statment write an ordinary sql statement) now go till Finish..now the default select method has changed..

now to use the stored procedure that u have changed do the same procedure and select an existing stored procedure option when we click the prevoius button and continue clicking the wizard until finish.

now u will be using the new stored procedure that has a new field that u have added..

i hope this helps


|||

The problem is that when I click next button on the "Choose methods to generate". I get this error message:

"The names specified for Fill Data table and Get data table can not be the same".

You see, there are the same right now, so I am not sure what I should choose... This is existing starter kit application...

|||

hi,

give different names for the filldata method and getdata method.. these are two different methods..

Eg

'FilldataAddUsers" and

"GetDataAddAddUsers "

Monday, March 12, 2012

Problems with joins

I'm having trouble with joins...

TableA includes the fields name, order_number and value1.
Tableb includes the fields order number and value2

I'm joining on Order Number.
I want to return Name, TableA.order_number, TableB.order_number, value1
and value2.

I want to return all order_numbers from TableA and any from TableB that
are in TableA.

My script currently has TableA LEFT OUTER JOIN TableB On
TableA.order_number = TableB.order_number

I know it is incorrect because the sum of TableA.Value1 is 100, but
after my left outer join with TableB the sum of Value1 is 50.

Any ideas?

Regards,
CiarnOn 12 Apr 2005 09:38:44 -0700, chudson007@.hotmail.com wrote:

>I'm having trouble with joins...
>TableA includes the fields name, order_number and value1.
>Tableb includes the fields order number and value2
>I'm joining on Order Number.
>I want to return Name, TableA.order_number, TableB.order_number, value1
>and value2.
>I want to return all order_numbers from TableA and any from TableB that
>are in TableA.
>My script currently has TableA LEFT OUTER JOIN TableB On
>TableA.order_number = TableB.order_number
>I know it is incorrect because the sum of TableA.Value1 is 100, but
>after my left outer join with TableB the sum of Value1 is 50.
>Any ideas?
>Regards,
>Ciarn

Hi Ciarn,

Can you post the complete query, please? Even better would be if you
include the DDL (CREATE TABLE statements) for the tables as well,
preferably including some sample data (posted as INSERT statements).

That will allow us to review your code, run some tests and come up with
a suggestion.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||Here is the script

The sum of Shpt_Leg_List_CLC changes between Script1 and Script2 and
the only change I think I have made is the join to TableB

Script1
SELECT Customer_Number AS Customer_Number, ID_Code AS ID_Code,
LEFT(Ship_Day, 4) AS Ship_Month, SUM(Shpt_Leg_List_CLC) AS
Shpt_Leg_List_CLC,
SUM(Shpt_Leg_Net_CLC) AS Shpt_Leg_Net_CLC,
SUM(Shpt_Leg_List_LC) AS Shpt_Leg_List_LC, SUM(Shpt_Leg_Net_LC) AS
Shpt_Leg_Net_LC,
SUM(Shpt_Leg_Ref_List) AS Shpt_Leg_Ref_List,
SUM(Shpt_Leg_Ref_Net) AS Shpt_Leg_Ref_Net, SUM(Shpt_Leg_Prod_Units) AS
Shpt_Leg_Prod_Units,
SUM(Shpt_Leg_Optn_Units) AS Shpt_Leg_Optn_Units,
SUM(Shpt_Leg_Supt_Units) AS Shpt_Leg_Supt_Units,
Shpt_Leg_MCC_Units AS Shpt_Leg_MCC_Units,
Department, Misc_Charge_Code AS TableA_DataV1, Order_Section
INTO TableA_DataV2
FROM TableA
GROUP BY Customer_Number, ID_Code, LEFT(Ship_Day, 4),
Shpt_Leg_MCC_Units, Department, Misc_Charge_Code, Order_Section
ORDER BY LEFT(Ship_Day, 4), Customer_Number, ID_Code, Department,
Shpt_Leg_MCC_Units, Misc_Charge_Code

Script2
SELECT TableA.Customer_Number AS Customer_Number, TableA.ID_Code AS
ID_Code,
LEFT(TableA.Ship_Day, 4) AS Ship_Month,
SUM(TableA.Shpt_Leg_List_CLC) AS Shpt_Leg_List_CLC,
SUM(TableA.Shpt_Leg_Net_CLC) AS Shpt_Leg_Net_CLC,
SUM(TableA.Shpt_Leg_List_LC)
AS Shpt_Leg_List_LC, SUM(TableA.Shpt_Leg_Net_LC)
AS Shpt_Leg_Net_LC,
SUM(TableA.Shpt_Leg_Ref_List) AS
Shpt_Leg_Ref_List, SUM(TableA.Shpt_Leg_Ref_Net)
AS Shpt_Leg_Ref_Net,
SUM(TableA.Shpt_Leg_Prod_Units) AS Shpt_Leg_Prod_Units,
SUM(TableA.Shpt_Leg_Optn_Units) AS
Shpt_Leg_Optn_Units, SUM(TableA.Shpt_Leg_Supt_Units)
AS Shpt_Leg_Supt_Units, TableA.Shpt_Leg_MCC_Units
AS Shpt_Leg_MCC_Units, TableA.Department,
TableA.Misc_Charge_Code AS TableA_DataV1,
TableA.Order_Section,
TableB.Sales_Order_Number
INTO TableA_DataV2
FROM TableA LEFT OUTER JOIN
TableB ON TableA.Order_Section =
TableB.Sales_Order_Number
GROUP BY TableA.Customer_Number, TableA.ID_Code, LEFT(TableA.Ship_Day,
4),
TableA.Shpt_Leg_MCC_Units, TableA.Department,
TableA.Misc_Charge_Code, TableA.Order_Section,
TableB.Sales_Order_Number
ORDER BY LEFT(TableA.Ship_Day, 4), TableA.Customer_Number,
TableA.ID_Code,
TableA.Department, TableA.Shpt_Leg_MCC_Units,
TableA.Misc_Charge_Code|||On 13 Apr 2005 01:37:09 -0700, chudson007@.hotmail.com wrote:

>Here is the script
>
>The sum of Shpt_Leg_List_CLC changes between Script1 and Script2 and
>the only change I think I have made is the join to TableB
(snip)

Hi Ciarn,

Does only the sum of Shpt_Leg_List_CLC change, or do all the other sums
change as well?

Did you factor in that the total from one group in query 1 may be
divided over several groups in query 2, due to the extra column in the
GROUP BY clause (TableB.Sales_Order_Number)?

Are you sure that the total from query 1 is HIGHER than the total from
query 2? I could explain a LOWER total, not a HIGHER total!

I see no obvious problems with the code you posted. If you want me to
investigate this further, you'll really have to poste CREATE TABLE and
INSERT statements as well, so that I can reproduce the problem on my
computer.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Wednesday, March 7, 2012

Problems with Date And Time

Hello everybody,

I have a problem with a date. I retrieve data from an Access database, where there are two fields, one for the date and one for the time. I have to join this two fields in my destination column, but I don't know how to do it...

I tried using a Derived column, in which I cast this two fields in string, concatenate them and then cast them back to datetime, but it doesn't work....

Does anyone knows how to resolve my problem?

Thanks

Did you get an error from SSIS when trying to parse the derived column code?

(DT_DATE)((DT_STR,4,1252)YEAR(<DATE_COLUMN>) + "-" + (DT_STR,2,1252)MONTH(<DATE_COLUMN>) + "-" + (DT_STR,2,1252)DAY(<DATE_COLUMN>) + " " + <TIME_COLUMN>)

|||

I get an error in using this string

(DT_DBDATE)(REPLACE((DT_STR,50,1252)Data,"/","-") + "T" + REPLACE((DT_STR,50,1252)Ora,".",""))

where "data" and "ora" are the fields with the date and the time I need

|||

can you try with this:
(DT_DATE)(REPLACE((DT_STR,50,1252)Data,"/","-") + " " + REPLACE((DT_STR,50,1252)Ora,".",":")). (I guess the datatype is datetime)

The replaces are only available if Data looks like "2006-03-13" and Ora looks like "20:15:10".

|||

Just as an aside...you might want to consider DT_DBTIMESTAMP for the reasons outlined here: http://blogs.conchango.com/jamiethomson/archive/2005/11/15/2399.aspx

As I said, this is an aside, it won't help you to parse the date out!

-Jamie

|||

I didn't know that :-) Thanks Jamie for the extra info.

So Teone, this is only a parsing problem. Your data type is not good to store date and time and the expression you're using isn't right either.
The 'T' for time (and not for two LOL) is really not needed.

Can you try with the expression I proposed in my second post?

|||it works except for seconds and minutes... they in fact are rounded to zero and to the next value up or down....|||it works except for seconds and minutes... they in fact are rounded to zero and to the next value up or down....|||

This is tuning then . You need to search for the right formatting of your input data and you'll find the way.

Problems with date

Hi, my name is MANUEL. I don't speak english very well...
Today I am working with SQLServer. I would want to compare two dateTime fields for to determine if two or more customers are connected in the same moment into my applications...
For example:
Begin date of connections:
16/01/2007 16.19.59
end date of connection
16/01/2007 16.25.23 for customers 01

Begin date of connections:
16/01/2007 16.20.59
end date of connection
16/01/2007 16.24.23 for customers 02

What i have to do!!!!
I must make this control to every hour of the day
Please Help!

Hi Manuel,

If I understand you question, you are looking to write a query that shows overlapping sessions.

If you start with a list of all the distinct start times, you can then use a correlated query to look for overlapping sessions (something like):

Code Snippet

select s1.app, st, (
select count(*)
from Sessions as s2
where
s1.app = s2.app

and s1.st >= s2.StartDateTime
and s1.st < s2.StopDateTime ) as Overlaps
from (
select distinct app, StartDateTime st
from Sessions
) as s1

Note that set based solutions around this type of problem can become really slow, really quickly! A cursor based solution can scale much better. You'd have to do some testing to see which would work best for you.

Hope that helps.

Jamie

|||

Here is a query that will retrieve all the connections that are overlapping.

Code Snippet

Select Conn1.Customer, Conn1.BeginDate, Conn1.EndDate,

Conn2.Customer, Conn2.BeginDate, Conn2.EndDate, *

From Connections Conn1, Connections Conn2

Where Conn2.BeginDate Between Conn1.BeginDate And Conn1.EndDate

And Conn1.ID <> Conn2.ID

I'm assuming the table name is called 'Connections' and that there is a primary key which is called ID. Here I've joined the table on itself looking for connections that have their start time between another connection's start and end time. I added 'Conn1.ID <> Conn2.ID' so that the query does not assume that the same connection is as an overlapping one.

I hope this answers your question.

Best regards,

Sami Samir

|||

This query might help you...

Code Snippet

Select
MainThread.CustomerId Customer
,MainThread.Startdate Customer1StartAt
,MainThread.Enddate Customer2EndAt
,ParlelThread.CustomerId ParllelWith
,ParlelThread.Startdate ParllelCustomerJoinAt
,ParlelThread.Enddate ParllelCustomerLeaveAt
,DateDiff(Mi, ParlelThread.Startdate, Case When MainThread.Enddate < ParlelThread.Enddate Then MainThread.Enddate Else ParlelThread.Enddate End ) TotalMinutesParllel
from AuditLog MainThread
Join AuditLog ParlelThread On
MainThread.Enddate > ParlelThread.Startdate And
MainThread.Startdate <= ParlelThread.Startdate
And MainThread.CustomerId <> ParlelThread.CustomerId
Order By 1

|||Sorry!I don't know SQL SERVER too

I have only one table which contains:
IDCustomers
Name
BeginDate
EndDate

My really problem is to abtain the list of cutomers whitch day,mount, years is the same and

have the same hour of logon.

I ask for new excuse for my English


|||

Try this :

Substitute your actual table name in <YourTable>

select BeginDate,IDCustomers,Name,EndDate

from <YourTable>

where BeginDate in

(

select BeginDate

from <YourTable>

group by BeginDate

having count(*) > 1

)

order by BeginDate,IDCustomers

Thanks.

Naras.

|||

The following query may help you...


Code Snippet

Select
MainThread.CustomerId Customer
,MainThread.Startdate Customer1StartAt
,MainThread.Enddate Customer2EndAt
,ParlelThread.CustomerId ParllelWith
,ParlelThread.Startdate ParllelCustomerJoinAt
,ParlelThread.Enddate ParllelCustomerLeaveAt
Into #Data
from <YourTable> MainThread
Join <YourTable>ParlelThread On
MainThread.Enddate > ParlelThread.Startdate And
MainThread.Startdate <= ParlelThread.Startdate
And MainThread.CustomerId <> ParlelThread.CustomerId
Order By 1

Select Customer, Customer1StartAt, Customer2EndAt From #Data
Union
Select ParllelWith, ParllelCustomerJoinAt, ParllelCustomerLeaveAt From #Data

Drop Table #Data

|||thanks to all… I have resolved the problem with one function.
you have been fast and kind
BYE

Saturday, February 25, 2012

Problems with adding data to wider table

I want to insert a record with fields let say"ProductCode, Name" to a table with records like "ProductCode, Name, NumberofItems". I get mismatching errors "Conversion from string "INSERT INTO dbo.t_Shopping(Productcod" to type 'Double' is not valid.". Note the missing last letter. ProductCode and Name are both varChars, NumberofItems is int in table and double in my code.

This is my insertion script ".CommandType = CommandType.Text = "INSERT INTO dbo.t_Shopping(ProductCode, Name, NumberofItems)SELECT ProductCode, Name, @.NumberofItems FROM dbo.t_Product WHERE ProductCode=@.ProductCode"

I have asked this question previously in an other mail, but probably because that thread was marked solved, no one answered.

The whole code is like this: I translated some names. I hope its still valid.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim NumberofItems As Double = 1
Dim conn As New SqlConnection("Data Source=DV2\SQLEXPRESS;Initial Catalog=testaus;Integrated Security=True")
Dim row As DetailsViewRow = DetailsView1.Rows(0)
Dim ProductCode As String = row.Cells(1).Text
Dim cmd As New Data.SqlClient.SqlCommand
Dim param As New SqlParameter()

TextBox1.Text = ProductCode

With cmd
.Connection = conn
.CommandType = CommandType.Text = "INSERT INTO dbo.t_Shopping(ProductCode, Name, NumberofItems)SELECT ProductCode, Name, @.NumberofItems_
FROM dbo.t_Product WHERE ProductCode=@.ProductCode"


.Parameters.AddWithValue("@.ProductCode", ProductCode)
.Parameters.AddWithValue("@.NumberofItems", NumberofItems) '
End With
Try
conn.Open()
cmd.ExecuteNonQuery()
Catch ex As Data.SqlClient.SqlException
Throw New ApplicationException("An error occurred while trying to insert the record")
Finally
conn.Dispose()
End Try

Regards

Leif

My Sql command code had problems, probably. I tried this (see below), but got still more unclearer error. "Incorrect syntax near ','.".I dont know if the problem is in sql query string or in code using 2 parameters,or in wrong variable types.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim NumberofItems As Integer = 1
Dim luku As Integer
Dim conn As New SqlConnection("Data Source=DV2\SQLEXPRESS;Initial Catalog=testaus;Integrated Security=True")
Dim row As DetailsViewRow = DetailsView1.Rows(0)
Dim ProductCode As String = row.Cells(1).Text

TextBox1.Text = ProductCode

Dim cmd As New SqlCommand("insert dbo.t_Shopping (ProductCode, Name, NumberofItems) select (ProductCode, Name,@.NumberofItems) FROM dbo.t_Product_
WHERE ProductCode=@.ProductCode", conn)

Dim partk, paramaar As New SqlParameter()
partk.Value = ProductCode
partk.SqlDbType = SqlDbType.VarChar
partk.Direction = ParameterDirection.Input
partk.ParameterName = "@.ProductCode"
cmd.Parameters.Add(partk)
paramaar.Value = NumberofItems
paramaar.SqlDbType = SqlDbType.Int
paramaar.Direction = ParameterDirection.Input
paramaar.ParameterName = "@.NumberofItems"
cmd.Parameters.Add(paramaar)
cmd.Connection.Open()
luku = cmd.ExecuteNonQuery() 'This gives errors
cmd.Connection.Close()

End Sub

Leif

|||

LISM:


Dim cmd As New SqlCommand("insert dbo.t_Shopping (ProductCode, Name, NumberofItems) select (ProductCode, Name,@.NumberofItems) FROM dbo.t_Product_
WHERE ProductCode=@.ProductCode", conn)

First, remove the () from the select query.

Second, make sure all the parameters are actually having some values.

Hope this will help.

|||

Thanks

Is there difference between NumberofItems and @.NumberofItems and so on. Variables without @. have a value, but with them don't. Besides, I now tried to @.NumberofItems =NumberofItems and it didn't help (got errors).

Whats next?

Leif


|||

It depends on what you want to use. @.NumberofItems seems to be what user typed in and NumberofItems seems to be coming from the table.. so its your call on which should go into the table.

|||

Thank you for an answer

It looks like I have misunderstood this.

NumberOfItem comes now from code. Its value is 1 now. And yes, someday it may come from the user. Then I try to put it in the Shopping table. I try to do it this way because in Shopping table there is an extra field called NumberofItems. Shopping is a shopping basket and it should contain amount field. The Product table is really a list of names and codes.

Query should work so that it looks for an iten whose code is in ProductCode or @.ProductCode. And then copies that some fields of that record plus NumberOfItems field to shopping basket.

I don't really know where the problem is, in code or in query.

Regards

Leif

|||

Just change your query to

INSERTdbo.t_Shopping (ProductCode, Name, NumberofItems)

SELECT ProductCode, Name,@.NumberofItems

FROMdbo.t_Product

WHERE ProductCode=@.ProductCode

as dhimant suggested and it would work.

|||

Sorry about the mess. But it works!

There was still some problem with code or query, and I wanted to ask more help. Anyway I tried the query in this code, and at first I got errors:"Incorrect syntax near ')'. This is my code without translation. I left out name field to get shorter lines. Tuotekoodi=Productcode, Osto~Shopping, Maara=numberOfItems and so on.

Dim cmd As New SqlCommand("INSERT dbo.t_Osto (Tuotekoodi, Maara) SELECT Tuotekoodi,@.Maara FROM dbo.t_Tuote WHERE Tuotekoodi=@.Tuotekoodi", conn)
cmd.Parameters.Add("@.Maara", SqlDbType.Int)
cmd.Parameters.Add("@.Tuotekoodi", SqlDbType.VarChar)
conn.Open()
cmd.Parameters("@.Tuotekoodi").Value = Tuotekoodi
cmd.Parameters("@.Maara").Value = Maara
luku = cmd.ExecuteNonQuery()
conn.Close()

The most difficult and interesting part was the fact that the IDE inserted some extra brackets () . I copy/pasted your code to an empty place in my code, and got many errors, thats ok. But at the same time IDE inserted couple of pairs of brackets there. And then I pasted the code with extra brackets to my code. That was quite difficult to see. I tend to trust Copy/paste. A nasty feature?

Probably that spoiled my earlier attempts, also.

And lets not forget, it works, thanks.


Leif