How Do You Insert Into Two Tables From One Insert? Or Even How Would You Using Two Inserts?
Mar 18, 2007
I currently insert into one table with:
SqlCommand comm = new SqlCommand("INSERT INTO UsersTable (UserName, Password, Email) VALUES (@person, @pass, @email)", sqlConnection);
comm.Parameters.AddWithValue("@person", usrnmeLbl.Text);
comm.Parameters.AddWithValue("@pass", hiddenpassLbl.Text);
comm.Parameters.AddWithValue("@email", hemailLbl.Text);
but I realized that there's another table related to this table and I need to have something go in it so that the users data will be recorded at the same pace. So I tried:
SqlCommand comm = new SqlCommand("INSERT INTO UsersTable, FatherHistTable (UserName, Password, Email), (Father) VALUES (@person, @pass, @email), (@father)", sqlConnection);
comm.Parameters.AddWithValue("@person", usrnmeLbl.Text);
comm.Parameters.AddWithValue("@pass", hiddenpassLbl.Text);
comm.Parameters.AddWithValue("@email", hemailLbl.Text);
comm.Parameters.AddWithValue("@father", fthrsNmeLbl.Text);
Not working, so I am thinking I must do two inserts:
SqlCommand comm = new SqlCommand("INSERT INTO
UsersTable (UserName, Password, Email) VALUES (@person, @pass,
@email)", sqlConnection);
comm.Parameters.AddWithValue("@person", usrnmeLbl.Text);
comm.Parameters.AddWithValue("@pass", hiddenpassLbl.Text);
comm.Parameters.AddWithValue("@email", hemailLbl.Text);
SqlCommand comm2 = new SqlCommand("INSERT INTO
FatherHistTable (Father) VALUES (@father)", sqlConnection);
comm2.Parameters.AddWithValue("@father", fthrsNmeLbl.Text);
Is that the only way to go about it then? Thanks in advance for any explanations.
View 26 Replies
ADVERTISEMENT
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
Aug 22, 2006
Hi there,
I'm having a problem where the data taken from the textboxes is being inserted into a table twice. I looked online and someone on another forum was experiencing the same problem. His solution was making the "submitdsabledcontrols" attribute of the form false. That hasn't fixed the issue for me.
Below is my code. I'm still learning all this so this is just a test page, hence the wacky naming conventions.
When the button click calls Button1_Click, all it runs is "SqlDataSource1.Insert()"
Any ideas?
<%@ Page EnableEventValidation="false" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server">
<form id="form1" submitdisabledcontrols=false>
<br />
<asp:Label ID="Label1" runat="server">Name</asp:Label>
<asp:TextBox ID="NameTextBox" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label">Number</asp:Label>
<asp:TextBox ID="NumberTextBox" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Label">Salary</asp:Label>
<asp:TextBox ID="SalaryTextBox" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_click" />
</form>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString1 %>" DeleteCommand="DELETE FROM [Table1] WHERE [TableID] = @original_TableID" InsertCommand="INSERT INTO [Table1] ([Name], [Number], [Salary]) VALUES (@Name, @Number, @Salary)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Table1]" UpdateCommand="UPDATE [Table1] SET [Name] = @Name, [Number] = @Number, [Salary] = @Salary WHERE [TableID] = @original_TableID">
<DeleteParameters>
<asp:Parameter Name="original_TableID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Number" Type="String" />
<asp:Parameter Name="Salary" Type="Decimal" />
<asp:Parameter Name="original_TableID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:ControlParameter Name="Name" Type="String" ControlID="NameTextBox" />
<asp:ControlParameter Name="Number" Type="String" ControlID="NumberTextBox" />
<asp:ControlParameter Name="Salary" Type="decimal" ControlID="SalaryTextBox" />
</InsertParameters>
</asp:SqlDataSource>
</asp:Content>
View 1 Replies
View Related
May 15, 2008
Greetings
Got bulk insert thing going real nice thanks to your feedback! But now I notice that the BULK INSERT creates 2 identical rows while the flat file has the column headers and then corresponding row, just one row.
Why would it do that. Interestingly if the data file and format file are residing on a shared folder on SQL 2005, and I ran the BULK INSERT from studio it only inserts one row. But when I do BULK INSERT via user interface it creates 2 rows. What is going here.
View 10 Replies
View Related
Jul 25, 2005
m inserting some data in big-sized field
and small-sized fields, data of varchar type, int's, dateTime, and
others... i am using something called a stored procedure to add data
into a table.. now when i execute the stored procedure my data gets
truncated (although i made the sizes for my fields ridiculously big
like 1000 just in case) for example if i want to enter Jasmine it only
inserts 'J' in the field
I am sure there's something wrong in the stored procedure, and I am
guessing it's a problem of using single vs. double quotes and stuff
like that within my insert statement...
the following is my stored procedure:
CREATE procedure addLabor
@lName varchar,
@fName varchar,
@mName varchar,
@title varchar,
@craft varchar,
@lastFour varchar,
@SSN varchar,
@dateOfHire varchar,
@currentProj varchar,
@status tinyInt,
@project_id int,
@updateBy varchar,
@updateDate varchar,
@address varchar,
@email varchar,
@phone varchar,
@zip varchar,
@myfeedBack varchar,
@ethnicity varchar,
@userID int
as
BEGIN
SET NOCOUNT OFF
DECLARE @newid INT
insert into laborPersonal ( lName, fName, mName, title, craft,
lastFour, SSN, dateOfHire, currentProj, status, project_id,
updateBy,
updateDate, address, email, phone, zip, ethnicity)
VALUES
(@lName , @fName , @mName , @title , @craft , @lastFour , @SSN ,@dateOfHire , @currentProj ,
@status, @project_id , @UpdateBy, @UpdateDate , @address , @email , @phone , @zip , @ethnicity )
SELECT @newid = SCOPE_IDENTITY()
insert into feedBack
(lID, feedBack, userID, project_id)
values
(@newid ,+'
+@myfeedBack + ',
+@userID ,
@project_id )
SET NOCOUNT ON
END
GO
When i use 2 single quotes it insert the following string: "@lName" not the actual value of the variable @lName
my exec statement is this:
EXEC addLabor 'Razor', 'Nazor', 'mid', 'Mr', 'Carpenter Forman',
'1234',
'keOWVozC+wmBvaqgkVkZci5y4vFLdTKfZOVG4C6BSN6H2MBP6pdsIWA0SdPAlPJra0EjEj+uXI/kXSiBuwwnKQ==',
'6/27/2005 12:00:00 AM' , 'O.C. Public Library', 1, 3, '3', '7/25/2005
2:38:02 PM', '1233 Shady Canyon, Irvine', '', '', '12345',
'123-12-1234', 'African American', '3'
I appreciate any help or hints
thanks to all
View 1 Replies
View Related
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
Apr 22, 2004
Hi,
Currently, I'm using the following steps to migrate millions of records from Foxpro tables to SQL Server tables:
1. Transfer Foxpro records to .dat files and then bcp to SQL Server tables in a dummy database. All the SQL tables have the same columns as the Foxpro tables.
2. Manipulate the data in the SQL tables of the dummy database and save the manipulated data into the SQL tables of the real database where the tables may have different structure from the corresponding Foxpro tables.
I only know the following ways to import Foxpro data into SQL Server:
#1. Transfer Foxpro records to .dat files and then bcp to SQL Server tables
#2. Transfer Foxpro records to .dat files and then Bulk Insert to SQL Server tables
#3. DTS Foxpro records directly to SQL Server tables
I'm thinking whether the following choices will be better than the current way:
1st choice: Change step 1 to use #2 instead of #1
2nd choice: Change step 1 to use #3 instead of #1
3rd choice: Use #3 plus manipulating in DTS to replace step 1 and step 2
Thank you for any suggestion.
View 2 Replies
View Related
Dec 19, 2006
Please i need to insert two tables at a time. One is Delivaries and the other is DelivaryDetails. This is the Structure:
DelivariesDelivaryId...........Int Primary Key IdentityDelivaryNo.........nvarcharDelivaryDate......datetime
DelivaryDetailsDelivaryId............Int Primary Key Foreign KeyProductId............Int Foreign KeyQty....................Int
I have created a StoredProcedure named InsertDelivaries
CREATE PROCEDURE InsertDelivaries@DelivaryId int output,@DelivaryNo nvarchar(20),@DelivaryDate datetime
AS
insert into Delivaries values(@DelivaryNo,@DelivaryDate)
but this does not insert the records as expected. Please help
View 5 Replies
View Related
Apr 10, 2007
hello..
I think this is common question, but i still dont get answer from all past topic and thread.
My problems is:
I have two tables,
1) company_info (com_ID(Primary key with increment int), name, add, contact_no)
2) company_detail(com_ID(Primarykey without increment), product, quantity)
I want capture the data com_ID from 1st table and at the same time I want to insert into 2nd tables. How the way??
currently I do in table adapter in data set.
I also looking how to use store procedures? my knowledge about store proceduree is zero and really need articles or tutorial from any website. anylink?
One more things, I also which part i should do the relationship, in dataset or at database diagram?
I really lack in this database knowledge
Thank you
View 3 Replies
View Related
Dec 18, 2007
hello my friends
i have a database with 5 tables : 1-Company 2-Activity 3-Product 4-Project 5-Telephone
each table have a one to many relation with Company Table ! i mean a Company can has many Activities,Products,Projects,Telephones i want to insert in tables at a same time insert into Company table ! i know that i should first insert into company Table and get CompanyID that need to insert in other tables. i hear that i can do this with define a VIEW of joining these tables and use trigger!i dont know how !?
I'll appreciate you to help me :O)
View 4 Replies
View Related
Feb 22, 2008
I am using Framework 3.5 with VS2008 writing VB code to put and get data in a SQL 2005 Server database.
How to fill out a form, and on one submit button click, send some information into one database table and different information into a different table?
Those tables of mine have a common key, but one is about where and when and what work needs to be done and the other is about authorization, departments and funds.
I’d just think that I should be able to do that in one InsertCommand="INSERT INTO …� statement and not have to code a whole new <asp:SqlDataSource ID="SqldsDOIT" runat="server" interface for the second table … which is the work-around that I can do … it just seems ignorant to me, when we are told to keep like-things in separate tables (normalization).
In other words, the following fails to run ... if I only INSERT INTO Job( or only INSERT INTO Signatory( ... it's all good.A little help please. I've scanned through the forums, but not found exactly this addressed. <asp:SqlDataSource ID="SqldsDOIT" runat="server" ConnectionString="<%$ ConnectionStrings:DOITWorkOrderConnectionString %>" SelectCommand="SELECT FROM [Job] JOIN [Signatory] ON Job.Jobnumber = Signatory.Jobnumber" InsertCommand="INSERT INTO Job(Datereq, ..., Jobcomm) VALUES(@Datereq, ..., @Jobcomm) INTO Signatory(BillProgram, ..., Sigemail) Values(@BillProgram, ..., @Sigemail)"> <InsertParameters>
View 4 Replies
View Related
Sep 5, 2001
I want to insert records from two tables into one table as the record is concatenated from both the tables and then put it into the one table.
How can we do that so that i can take the records from the one table..?
CREATE PROCEDURE SP_P31
AS
select 'CA'+'|'+COMPANY+'|'+COMPANYNAME+'|'+CUSTOMERNUMBE R+'|'+COMPANYPHONE
+'|'+COMPANYFAX+'|'+FEDTAXID+'|'+DUNSNUMBER+'|'+S1 099+'|'+DUNSSUFFIX+'|'+convert(char,ADDRESSSEQ)
+'|'+COUNTRY+'|'+ADDRESSTYPE+'|'+ADDRESS1+'|'+ADDR ESS2+'|'+ADDRESS3+'|'+ADDRESS4
+'|'+CITY+'|'+STATE+'|'+ZIP+'|'+FAXNUMBER hello1 into temp32
from v4
select 'CT'+'|'+COMPANY+'|'+CONTACTNAME+'|'+CONTACTTYPE+' |'+CONVERT(CHAR(10),CONTACTADDRESS)
+'|'+PHONE+'|'+FAX+'|'+TITLE hello INTO temp32
from v3
View 3 Replies
View Related
Mar 8, 1999
Does SQL allow you to insert data into 2 related tables simultaneously?
I have a form where the user enters in Name, Age, SocialSecurity,
Address. The Address table is a separate table than the Individual
table. How do I insert into both ??? Both tables are tied with a unique Individual_ID which is system generated.
I am using a stored procedure
Thanks alot!!
Joyce
View 1 Replies
View Related
Oct 19, 2007
I posted this question previously but am now getting another error and fixing it (months ago). I am trying insert The ID2 column (pk) from table 2 into ID2 column (fk) of table 1. What the T-SQL is trying to do is check to see if the record in table 2 already exists in then just pass the value to the insert query for table 1. If the record does not exist then insert data into table 2first then perform the table 1 insert.
This SP works fine if the user does not exist in table 2. However, if the user does exist in table2 then instead of passing the ID, a null value is passed.
Can anyone tell me why the first query does not work? If there is an easier way of doing this then I am all ears.
Thank you
DECLARE @IdentityHolder int
BEGIN TRANSACTION
IF EXISTS (SELECT ID2 FROM [tbl2] WHERE ID2 = @ID2)
BEGIN
(SELECT ID2 FROM [tbl2] WHERE ID2 = @ID2)
END
ELSE
BEGIN
INSERT INTO [tbl2] ([ID2], [FN], [LN], emailAdd])
VALUES ( @ID2, @fName, @lName, @emailAdd)
END
COMMIT
SET @IdentityHolder = (ID2)
INSERT INTO [tbl1]([ID2], [event])
VALUES (@ID2, @event)
View 14 Replies
View Related
Dec 12, 2007
Hi i have a stored prodedure which inserts into a local table then inserts into a remote table this works fine, what i need to do is.
INSERT ONTO TABLE A
THEN GET THE MAX(ID) OF THE RECORD INSERTED
THEN INSERT THAT MAX(ID) INTO TABLE B
i have created a parameter called @WebID but how do i give it the value of the MAX(ID) before i insert into tableB
Many thanks
View 2 Replies
View Related
May 18, 2008
Good evening every body.
I have 3 tables ( customer, product and order).
Customer table contain customer_id as a primary key
Product table contain product_id as a primary key
Order table contain both customer_id and product_id
I want to insert the values from customer and product to order.
Any help?
View 7 Replies
View Related
Jun 30, 2006
Coming from an asp world, I am totally lost on this one.
I have two tables.
tblUsers and tblUserInfo
I have a gridview that gives me the list of users and when selected, it gives me the detailsview of the the record. However, When I need to add a new user, I am trying to add that user into tblUsers (which happens with no problems), and then add a record, using the same user number (UserID) has the key or ID for the tblUserInfo.
So basicly, when I create a new user in tblUsers I want to create a record in tblUserInfo with the same userid.
In ASP, this takes me minutes... I have been trying to figure this out for weeks.
vs2005, sql express.
Thanks.
View 1 Replies
View Related
Feb 6, 2007
Hi, I have some problem with inserting data into two separate table which are connected via foreign key like in this example:Students (id_s, name, id_subject)Subjects (id_subject, name)So the point is to add a new student and subject for that chosen student. You have to make two inserts right? but how to pass the primary key to the table with foreign key? The form consists of three texbox: name, name_of_subject. Both id_s and id_subject are increment automatically. Any idea how to do it? I would be very grateful for the working code.Thanks in advance and best regards,N.
View 5 Replies
View Related
Oct 16, 2007
I have 3 tables, Type, Subtype, and Subtype2. All which are related by the ID of preceding table. Using a 3 textboxes and a button I want to insert new Types and subtypes to the tables. How do I go about identifying the new types new ID insert it in to the other tables? I am using ASP.net (vb) with sql server.
View 3 Replies
View Related
Nov 25, 2007
Hi,I need to make an insert into two tables connected to each other via foreign and primary key. The point is - I cannot use stored procedures or triggers. That tables looks like this: Candidate(ID, Name, Surname, Class) and Candidate_Exam(ID, date). ID in Candidate_Exam is a foreign key. When you insert a new record into Candidate, another one need to be inserted into Candidate_Exam with the same ID. Can anyone help? It is supposed to be an easy assigment so maybe I just have a bad approach.Regards,N.
View 3 Replies
View Related
Apr 22, 2008
Hi i want to insert a tables from one database to another based on unique key
View 2 Replies
View Related
May 12, 2008
Hi,
I'm trying to update 2 tables in SQL (say 2 Costumers table). 1 Lists all costumers per location( so 1 costumer can be placed in multiple locations), while the other is by location with contact details.
Is it possible for me to update both pages in 1 web update page?????
Thanks in advance.
View 3 Replies
View Related
May 12, 2005
hi,
i have got a problem, iam creating an asp.net application, but i pretend to insert data in two different tables, but i have no ideia how to do this.Can you help to solve this problem? please..........
View 3 Replies
View Related
May 12, 2005
hi,
iam creating an asp.net application the database is created on the SQLSERVER, but i have a problem, i pretend to insert data in to 2 tables and i have no ideia how to do this. Can you help me to solve this problem? Please.....
View 1 Replies
View Related
Jun 6, 2006
Hi I was watching this beginner webcast
Lesson 8: Obtaining Data from a SQL Server 2005 Express Edition Database
http://msdn.microsoft.com/vstudio/express/visualcsharp/learning/#beginners
I tried to do the same exact thing.
But when I tried to insert data in the newly created table I got the follwoing error window:
Invalid value for cell (row1, column 2)Then changed value in this cell was not recognized as valid..Net Framework Data Type: Byte[]Error Message; You cannot use the Result pane to set this Field data to values other than NULL.
Type a value appropriate for the data type or press ESC to cancel change.
Any Idea why thing happing.
View 3 Replies
View Related
Jun 13, 2006
Need some help. In my db I created 3 tables. 1- tblClient 2- tblCategories 3- tblClient_Cat ( colums: 1) client_id 2) cat_id).What I'm trying to do is create a sp to insert data from a web form into the tblClient and into the tblCat using the same sp. this is all I got so far.CREATE PROCEDURE [usp_insetClient](@ClientName varchar(25),@Contact varchar(100),@Tel char(13),@Fax char(13),@WebAdd varchar (250),@email varchar(250),@CatID int) ASBegininsert tblClient(Client_name,client_contact,Lient_tel,client_fax,client_webadd,client_email)values(@ClientName,@Contact,@Tel,@Fax,@WebAdd,@email)select @@identityinsert tblclient_cat(cat_id,client_id)values(@Catid,@@identity)(I tried to use this sp but didnot work)as you can see I need help inserting the client_id just created by the db into the tblclient_cat since the cat_id is passed from the web formThanksErnesto
View 1 Replies
View Related
Aug 3, 2001
i need to insert data into 2 tables. first in one, and the id of the register i just inserted is a field from the register in the other table (+ other data). inserting in this 2 tables should be invisible to the user so it has to be done automatically.
the dumb way i guess would be using 2 ADODB.recordsets (rs,rs1). first insert in one store the id in a var (after rs.update, rs.movelast, var=rs.fields("id")) and after this inserting a register in the new recordset (rs1)
is there a better way to do it?? any ideas??
thanx
View 2 Replies
View Related
Aug 6, 2007
hi guys,
can someone please tell me the best ways to insert data into multiple related tables .
cheers guys
andy
View 2 Replies
View Related
Oct 18, 2006
Hello
for MS SQL 2000
I am having MyTable with 7 columns : A,B,C,D,E,F,G
i want to
INSERT INTO myTable
SELECT A,B,C,D FROM FirstTable WHERE FirstTable.ID > 100
and the columns E,F,G :
E = 1
F = SELECT Max(ID) AS F FROM SecondTable
G = 0
how can i do it ?
i would like to create a stored procedure
thank you
View 2 Replies
View Related
May 20, 2008
Hi, i need to create a stored procedure that will take data from one table and insert it into one tabe.
I have 3 tables
tblTest is the table that i need to take the informations from.
intD1 to intD4 is a score
I don't know if iexplain my sefl correctly tks in advance!
tblTest
1 , 2 , 'A', 'B', 0 , 1 ,2 , 4
i need this
tblResultat
1, 2, 'A','B'
tblResultatXReponse
1,1,0,0
2,1,1,1
3,1,2,2
4,1,4,3
tblTest
intTestId autonumber
intCoursId
strCodeAbsent1
strCodeAbsent2
intD1
intD2
intD3
intD4
tblResultat
intResultatsId autonumber
intCoursId
strCodeAbsent1
strCodeAbsent2
tblResultatXReponse
intResultatXReponseId autonumber
intResultatsId
intReponseDesc
intOrdre
View 5 Replies
View Related
Oct 30, 2013
I have those 3 tables (sales,source, sales, sales_details),
Sales_source (table)
id, name
1 Office
2 Post
3 Web
Sales (table)
id, saleid, customer, source, date
01, 230, bill din, 1, 2013-10-22
Sales_details (table)
id, saleid, object, delivery, date
01, 230, card, no, 2013-10-23
02, 230, box, yes, 2013-10-24
03, 230, car, no, 2013-10-31
And I want to create if is possible one insert command
And make the user complete the details of Sales_details (that they have inner join for the sales_source table so he can see only the sales_source_name and behind the sales_source_id to be stored)
And after to be able to add in as many [sale_details] he need for the select sale…
Is this possible to be done with one command ???
I think is not possible as i have made a small research on the web, and i will need to make one insert for the sales (table) independent and after to programming i guess a way to open the sale_details and add the rest….
View 3 Replies
View Related
Oct 11, 2006
Hi,
I am using sqlServer 2000.I want to insert as well as update Two Tables at the Same Time using storedprocedure.Both My Tables Have the Same columns only difference being the name.My Tables are,
ADDRESS AND ADDRESSBOOK and their values are Name, Address, Place,
Date,City.
How can achieve this task using stored Procedures.?
Any Help would be appreciated....
Thanks...
View 8 Replies
View Related
Jul 23, 2005
Three tables (all new, no data) will receive data from dBase and betransposed into them...All three have auto generated IDENTITY columnsand pk and fk constraints. Can someone provide me with anunderstandible sample?Thanks,Trint
View 3 Replies
View Related