Copy or Save As

johmolan

Well-known member
Joined
Oct 11, 2008
Messages
129
Programming Experience
Beginner
Hi,

I have a relation database, it looks some thing like this.

Customer1 --> Order1 --> Process1=value1
--> Process2=value2
--> Process3=value3

The qustion is, is it possible to copy theese values and into

Customer2 --> Order1 --> Process1=value1
--> Process2=value2
--> Process3=value3
If I want to make an order based on the values from customer 1?

is it possiple to copy all values regardign customer 1 and past it into customer 2 or make some kind of save as buttomn to make i work?
 
My next problem comes when I want to add an order.

I use the same method to add ordreID:
Dim OrdreID As Integer
Dim MaxOrdreID As Integer
conn.Open()

myScalarQuery2 = " Select Max(OrdreID) As OrdreID From Ordre"
Dim myCommand2 As New SqlCommand(myScalarQuery2, conn)
OrdreID = myCommand2.ExecuteScalar()
conn.Close()
MsgBox(OrdreID)
MaxOrdreID = OrdreID + 1
MsgBox(MaxOrdreID)

The msgboxes are there only to check if it is returning the right value.

Then I want to insert order info based on the values allready in the OrdreTableAdapter.

I tried the code:
OrdreTableAdapter.Insert(OrdreID, @Ordedato, @Kalkyle_opprettet, @Leveringsdato, @Virkelig_leveringsdato, @Hovedtegningnr, @Ordre.Produkttype, _
@Materialtype,@Konstruktordato, @Kalkyle_utarbeidet, @Etterkalkyle_utarbeidet, @Tegningsrevisjon,MaxKundeID, @Status)

But I get errors that expression is expected.
and I do not understand it
 
I have now made some progress.

Can someone please take a look at my code and tell me why it only imports the last row?

Dim dtPros18 As DataTable
Dim dtblPros18 As DataTable
Dim i As Integer
Dim ID As Integer
Dim MaxID As Integer
Dim myScalarQuery3 As String
conn.Open()
myScalarQuery3 = " Select Max(ID) As ID From Prosess_18"
Dim myCommand3 As New SqlCommand(myScalarQuery3, conn)
ID = myCommand3.ExecuteScalar()
conn.Close()
MsgBox("ID = " & ID)
MaxID = ID + 1
MsgBox("MaxID = " & MaxID)

dtblPros18 = Kalkyle1DataSet.Tables("Prosess_18")
dtPros18 = dtblPros18.Clone
Dim copyRows3() As DataRow = _
dtblPros18.Select("OrdreID = 1")

i = MaxID
For Each copyRow In copyRows3
dtPros18.ImportRow(copyRow)
dtPros18.Rows(0)("OrdreID") = MaxOrdreID
i = i + 1
MsgBox("i = " & i)
dtPros18.Rows(0)("ID") = i
Next

Dim copyRows4() As DataRow = _
dtPros18.Select("OrdreID = '1'")
For Each copyRow In copyRows4
'Kalkyle1DataSet.Tables("Prosess_18").ImportRow(copyRow)
Next
DataGridView1.DataSource = dtblPros18
 
You are making this incredibly difficult for yourself. SQL will do all the work for you, if you let it. Example:-

VB.NET:
INSERT INTO
  Customers
SELECT
  (SELECT MAX(Customers.ID) + 1 FROM Customers) AS ID,
  Customers.FirstName,
  Customers.LastName
FROM
  Customers
WHERE
  Customers.ID = 79
 
Johmolan,

I agree with InertiaM; your approach is overly complicated. Seperate out SQL Tasks from Application.

Software Development is the balance of load and ergonomics.

Standard design approaches are :

3 Major phases
User Interface, Application Class Handling, and Data Manipulation

You should view anything that is SQL as Data Manipulation; if SQL can do it; generally let SQL handle it.

As for the answer to your question
Can someone please take a look at my code and tell me why it only imports the last row?

VB.NET:
Dim copyRows3() As DataRow = _
dtblPros18.Select("OrdreID = 1")

i = MaxID
For Each copyRow In copyRows3
dtPros18.ImportRow(copyRow)
dtPros18.Rows(0)("OrdreID") = MaxOrdreID
i = i + 1
MsgBox("i = " & i)
dtPros18.Rows(0)("ID") = i
Next

Minus the spelling mistakes, and grammer (you should clean this up).

OrdreID = 1 is your select statement; is there multiple OrdreID's that equal 1? What is an "psuedo example" of your data recordset.
 
I am sorry I do not understand what "psuedo example" means but to answer your first question, yes I have 10 rows in that table where OrdreID equal 1. in that table the forreign key is OrdreID.

And where is the spelling mistakes you are refering to?
 
Back
Top