Showing posts with label values. Show all posts
Showing posts with label values. Show all posts

Monday, March 12, 2012

Instalation MSDE failled !

Hello,
I'm trying to install MSDE but it fails.
I notice thatthe install log has several return values 3 wich means
problems.
...
Starting custom action InstallSQLAgentSecurity
InstallSQLAgentSecurity failed (AHFTSH,LocalSystem,87).
Action ended 11:25:35: InstallFinalize. Return value 3.
...
Start custom action DeferProperties
Defer Properties returns: 0
MSI (s) (48:B4) [11:25:40:093]: Executing op:
End(Checksum=0,ProgressTotalHDWord=0,ProgressTotal LDWord=0)
MSI (s) (48:B4) [11:25:40:093]: Error in rollback skipped. Return: 5
MSI (s) (48:B4) [11:25:40:109]: Calling SRSetRestorePoint API.
dwRestorePtType: 13, dwEventType: 103, llSequenceNumber: 246, szDescription:
"".
MSI (s) (48:B4) [11:25:40:171]: The call to SRSetRestorePoint API succeeded.
Returned status: 0.
MSI (s) (48:B4) [11:25:40:171]: Unlocking Server
MSI (s) (48:B4) [11:25:40:171]: PROPERTY CHANGE: Deleting UpdateStarted
property. Its current value is '1'.
Action ended 11:25:40: INSTALL. Return value 3.
...
MSI (s) (48:B4) [11:25:40:328]: MainEngineThread is returning 1603
MSI (s) (48:94) [11:25:40:328]: Destroying RemoteAPI object.
MSI (s) (48:30) [11:25:40:328]: Custom Action Manager thread ending.
MSI (c) (28:3C) [11:25:40:328]: Back from server. Return value: 1603
MSI (c) (28:3C) [11:25:40:328]: Decrementing counter to disable shutdown. If
counter >= 0, shutdown will be denied. Counter after decrement: -1
Action ended 11:25:40: INSTALL. Return value 3.
...
=== Logging stopped: 21-11-2007 11:25:40 ===
MSI (c) (28:3C) [11:25:40:359]: Note: 1: 1708
MSI (c) (28:3C) [11:25:40:359]: Product: Microsoft SQL Server Desktop
Engine -- Installation operation failed.
MSI (c) (28:3C) [11:25:40:375]: Grabbed execution mutex.
MSI (c) (28:3C) [11:25:40:375]: Cleaning up uninstalled install packages, if
any exist
MSI (c) (28:3C) [11:25:40:375]: MainEngineThread is returning 1603
=== Verbose logging stopped: 21-11-2007 11:25:40 ===
Solutions ?
Regards
Antonio Ferreiar
Andrea,
Thanks. Problem solved.
Antonio
"Andrea Montanari" <andrea.sqlDMO@.virgilio.it> escreveu na mensagem
news:5qj194F10cgomU1@.mid.individual.net...
> hi Antonio,
> Antonio Ferreira wrote:
> have you already seen http://support.microsoft.com/kb/829386/en-us ?
> regards
> --
> Andrea Montanari (Microsoft MVP - SQL Server)
> http://www.asql.biz http://italy.mvps.org
> DbaMgr2k ver 0.21.0 - DbaMgr ver 0.65.0 and further SQL Tools
> -- remove DMO to reply
>

Friday, March 9, 2012

Insertion with single quotes problem

I have a problem with inserting a string with single quotes. For instance,

string testme = "we don't have anything";

insert into tableone (buff) values ("'" + testme + "'");

I get an error with the word "don't" with single quote. But if I delete the single quote "dont" then it is okay. Is is a bug in sql 2005? Please help. Thanks.

blumonde

The best bet is to use parameters. Building the SQL String as you are can cause all sorts of problems.

Absent that, you need to "Escape" the apostrophe. SO, do the following...

string testme = "we don''t have anything";

Note there are 2 apostrophes in a row...

|||

douglas.reilly:

The best bet is to use parameters. Building the SQL String as you are can cause all sorts of problems.

Absent that, you need to "Escape" the apostrophe. SO, do the following...

string testme = "we don''t have anything";

Note there are 2 apostrophes in a row...

Hi Douglas,

The problem is that end-users write those statements and hit insert. And they don't type two apostrophes. I can't "escape" it. Thanks.

blumonde

|||

You then have two choices.

1.Use parameters.

2. Search the string for ' and replace it with '' (two apostrophes). Of course users are not going to use two apostrophes.

|||

douglas.reilly:

You then have two choices.

1.Use parameters.

2. Search the string for ' and replace it with '' (two apostrophes). Of course users are not going to use two apostrophes.

I will try using parameter first. Thanks.

blumonde

|||

Parameters did it for me. Thanks.

blumonde

Wednesday, March 7, 2012

Inserting XML values

" Insert Into...Value" seems to be the command for inserting new data into an XML Doc. I have also seen people using "Insert...Value" without the "Into" keyword. Is there a difference between "Insert" and "Insert Into"?

There is no difference. 'INTO' is optional keyword for INSERT ... VALUES() statement. It's not only for insert xml value, but for all other sql types.|||thank you :-)

Inserting with DTS in IDENTITY table

Hi

I need to insert values from a text-file to a table with a primary key as identity. In the text file I have no idea of the primary key values and i get "foreign key constraint violation" when trying to import null values into the column.

How can I solve the problem? With ordinary insert-statement there is no problem since the table generates identity- key values automatically. Is there a possibility to generate identity values with DTS-import?

Bjrnyes.

you just need to not map anything to the primary key column. In the wizard, you need to hit the transform button and make and under the column mappings make sure ignore is selected. If you are using the DTS desginer, you need to get rid of the mapping on your transform data task under the transformations task.

Inserting varchar to Decimal/Numeric

Hi,

Can we insert varchar values to Decimal(9,2)/numeric(9,2) fields?

I've a temp table with varchar values. I checked using isnumeric and all the values are numeric. But when I do the insert, it fails.

I was able to insert the following values:

000290165
000501075
000290165
000326314

But NOT the following:

010773474

All the values are 9 digits only.......

How can I convert this kind of numbers?

I need to convert all the 9 digit numbers to XXXXXXX.xx format.

(7digits.2 digits)

Thanks,

Siva.

I believe that in this case your expectations are incorrect. When I run:

Code Snippet

select inpt,
convert(numeric(9,2), inpt)
as convertedValue
from ( select '000290165' as inpt union all
select '000501075' union all
select '000290165' union all
select '000326314' union all
select '010773474'
) a

/*
inpt convertedValue
--
000290165 290165.00
000501075 501075.00
000290165 290165.00
000326314 326314.00

(5 row(s) affected)

Server: Msg 8115, Level 16, State 8, Line 1
Arithmetic overflow error converting numeric to data type numeric.
*/

The output is as expected. But I don't think that is what you are expecting. To get this correct try:

Code Snippet

select inpt,
convert(numeric(9,2), left(inpt,7) + '.' + right(inpt,2))
as convertedValue
from ( select '000290165' as inpt union all
select '000501075' union all
select '000290165' union all
select '000326314' union all
select '010773474'
) a

/*
inpt convertedValue
--
000290165 2901.65
000501075 5010.75
000290165 2901.65
000326314 3263.14
010773474 107734.74
*/

|||

Wow!! Great!

It worked like a magic!!

Thanks much...

Siva.

Inserting values Using Stored Procedure

Hi !
Iam working in asp.net in Visual Studio 2005. I tried to insert some datas from the webform's interfaces into the SQL Server 05 database using a stored procedure. Since iam new to asp.net,im confused wheather to use any command or anything else ? Kindly Help me !You can either directly execute the text command or can execute the same through a procedure.For that u need to write stored procedure in database. If you know that then go for it. But for that u need some extra coding in the front end. But performance wise using a stored procedure is better.|||

Quote:

Originally Posted by debasisdas

You can either directly execute the text command or can execute the same through a procedure.For that u need to write stored procedure in database. If you know that then go for it. But for that u need some extra coding in the front end. But performance wise using a stored procedure is better.


Can you give me some sample coding !|||

Quote:

Originally Posted by hellboss

Can you give me some sample coding !


The stored procedures is as follows

CREATE PROCEDURE TEST
@.field1 nvarchar(50),
@.field2 numeric(10)
AS
BEGIN
INSERT INTO TABLE1 (field1,field2) VALUES (@.field1,@.field2)
END

Hope this helps.

Thanks,

Inserting Values to Identity column.

Hi all,

I have a Table Which only have one column, and that column is also an Identity column. Does anybody know how to insert values to this table. I know that if I change the table and add another column I can solve this problem. But because I can't change the of the Database design provided to me by my architect, I have to find a solution for this.

Please help me......

Regards,
Sandarenu

you could use the statement "SET IDENTITY_INSERT ON" before the insert statement.

you can read about the usage from books online

Inserting Values Into Primary Key and Foreign Key Tables

I have two tables that I would like to insert values into at the same time
and would like help with the SQL statement to do so. One table (Member_Info)
has a PK and the other (Image_Info) a FK. The relationship the two tables
share is through the (E_Mail) column. Example structure:
Member_Info table columns:
First_Name
Last_Name
Birthday
E_Mail (PK)
Image_Info table columns:
E_Mail (FK)
Use
Name
Please Help! Thanks!Use INSERT TRIGGER in Member_Info table
"Willie Davis via webservertalk.com" wrote:

> I have two tables that I would like to insert values into at the same time
> and would like help with the SQL statement to do so. One table (Member_Inf
o)
> has a PK and the other (Image_Info) a FK. The relationship the two tables
> share is through the (E_Mail) column. Example structure:
> Member_Info table columns:
> First_Name
> Last_Name
> Birthday
> E_Mail (PK)
> Image_Info table columns:
> E_Mail (FK)
> Use
> Name
>
> Please Help! Thanks!
>|||Due to not determining what table will be filled by your code and what table
has to be filled "automagicaly", the following just depends on my guesswork.
CREATE TRIGGER TrgIns Member_Info
FOR INSERT
AS
BEGIN
INSERT INTO (EMail, Name)
SELECT EMail, COALESCE(FirstName,'') + ' ' + COALESCE(LastName,'') FROM
Inserted
END
I dont know wheter you Name column will store the First and the Lastname or
just one of it, but you should consider an Update Trigger to update this
information if its changed in the Primary Key Table. (Guess you sure wont
need it, if this just stores the name of the Member, even this is already
stored in the PK Table)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Willie Davis via webservertalk.com" <forum@.nospam.webservertalk.com> schrieb im
Newsbeitrag news:4183b2e7baef434899249fa71b414bf6@.SQ
webservertalk.com...
>I have two tables that I would like to insert values into at the same time
> and would like help with the SQL statement to do so. One table
> (Member_Info)
> has a PK and the other (Image_Info) a FK. The relationship the two tables
> share is through the (E_Mail) column. Example structure:
> Member_Info table columns:
> First_Name
> Last_Name
> Birthday
> E_Mail (PK)
> Image_Info table columns:
> E_Mail (FK)
> Use
> Name
>
> Please Help! Thanks!|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.
same time M<<
SQL works with one table at a time. Put you code into a stored
procedure, do two inserts and depend on DRI actions to maintain
integrity.

Inserting values into multiple tables

Hi. I have a primary key field in one table that is a foreign key field in another table. How do I write an INSERT statement that puts the value in both tables? Can this even be done?
On Thu, 20 May 2004 20:56:02 -0700, twright wrote:

>Hi. I have a primary key field in one table that is a foreign key field in another table. How do I write an INSERT statement that puts the value in both tables? Can this even be done?
Hi twright,
Not in one statement. You have to use two INSERT statements. If you want
to be sure that either both or none are executed, whatevert happens,
enclose them in a transaction:
BEGIN TRANSACTION
INSERT FirstTable (KeyColumn)
VALUES (17)
INSERT SecondTable (OtherKeyColumn, ForeignKeyColumn)
VALUES (231, 17)
COMMIT TRANSACTION
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

Inserting values into a column by selecting value from different table

Hi, I have a question regarding how to insert one column values into a table by selecting from different table..Here is the syntax..
----
insert into propertytable values (select lastvalue+incrementby from agilesequences where name='SEQPROPERTYTABLE', 13926, 0, 4, 1, 451, 1, 8, 1)

the first column in the propertytable will be... select lastvalue+incrementby from agilesequences where name='SEQPROPERTYTABLE'
How do I do that..Help PLZ..There are probably a number of ways to accomplish this...my preference would be to use a local variable to hold the value.

declare @.seq varchar(20); --[whatever...could be int]

select @.seq = lastvalue+incrementby
from agilesequences
where name='SEQPROPERTYTABLE';

insert into propertytable values (@.seq, 13926, 0, 4, 1, 451, 1, 8, 1);

--------
This should work unless I fat-fingered something.
There may be a way to do this in one pop...
--------|||INSERT INTO propertytable(ColName)
SELECT lastvalue+incrementby
FROM agilesequences
WHERE name='SEQPROPERTYTABLE'

What's this?

13926, 0, 4, 1, 451, 1, 8, 1

And You should supply a collist for the inserted tables...

Damn another fluff reply...|||There are probably a number of ways to accomplish this...my preference would be to use a local variable to hold the value.

declare @.seq varchar(20); --[whatever...could be int]

select @.seq = lastvalue+incrementby
from agilesequences
where name='SEQPROPERTYTABLE';

insert into propertytable values (@.seq, 13926, 0, 4, 1, 451, 1, 8, 1);

--------
This should work unless I fat-fingered something.
There may be a way to do this in one pop...
--------
Thanks a lot guys..
This worked for me.

Inserting values in a datetime field

Hi All,
I have a datetime column in a table on the SQL database. I need to insert
values into the datetime column from vb.net code. Here is my code:
dim nameval, str, qry as string
nameval = "abc"
str = "2005/03/16 14:20"
qry = "insert into tab1(name,dateval) values(" & "'" & nameval & "'," & "'"
str & "')"
...
..
ocmd.ExecuteNonQuery()
...
...
The error message that I get is as follows:
"The conversion of a char data type to a datetime data type resulted in an
out-of-range datetime value. The statement has been terminated. .Net
SqlClient Data Provider"
The problem I think is due to passing a string for a datetime field. My
question is, if I convert the string to datetype using CDate(str), then I
would have to again convert the date to string in order to form the insert
statement. So, the ultimate result will be again passing a string for the
datetime field!
I know that this is a simple syntax problem, which I don't seem to get right
!
Would anybody be able to give me insert statement for the above?
Thanks.
kdkd
Format the parameter as 'YYYYMMDD'
"kd" <kd@.discussions.microsoft.com> wrote in message
news:FC6115C1-BD59-4B91-A237-6E10C38EB3A8@.microsoft.com...
> Hi All,
> I have a datetime column in a table on the SQL database. I need to insert
> values into the datetime column from vb.net code. Here is my code:
> dim nameval, str, qry as string
> nameval = "abc"
> str = "2005/03/16 14:20"
> qry = "insert into tab1(name,dateval) values(" & "'" & nameval & "'," &
"'"
> str & "')"
> ...
> ..
> ocmd.ExecuteNonQuery()
> ...
> ...
> The error message that I get is as follows:
> "The conversion of a char data type to a datetime data type resulted in an
> out-of-range datetime value. The statement has been terminated. .Net
> SqlClient Data Provider"
> The problem I think is due to passing a string for a datetime field. My
> question is, if I convert the string to datetype using CDate(str), then I
> would have to again convert the date to string in order to form the insert
> statement. So, the ultimate result will be again passing a string for the
> datetime field!
> I know that this is a simple syntax problem, which I don't seem to get
right!
> Would anybody be able to give me insert statement for the above?
> Thanks.
> kd
>

inserting values for alias names within tables?

hi every1

I have a database table in which one of the fields is an alias for the identity field. That is the alias field self references the table and takes its value for the "id" field of tht table
as follows:
system_id int
system_name varchar(20)
sys_alias int
sys_pro varchar(80)
sys_values varchar(80)
so here the sys_alias takes wtever value the system assigns to the id field, system_id while inserting values into the table..
now my problem is i have to insert records into ths table frm aother tables using insert into...select from statements bt since the id values r enerated by the comp during value insertion i dunno how to give values fr the alias?

e.g insert into my_table(system_name,sys_alias,sys_pro,sys_values)
select x,(how to give ths field),y,z
from another_table
where...

neone who understood my problem and can help puhllezz post me a reply asap!
thnx:)

shuchiSounds like you'd have to do this in a trigger.|||what is the expression for the "alias" column? is it exactly the same value, or is it something like a character prefix plus the value?

perhaps you might consider using a view instead

rudy|||hi...
its exactly the same value..jus like a copy column fr the identity column..
i tried using max(syb_identity) and @.@.identity functions but they do not work specially since i put them in a sub query so theyre not calculated recursivelye but just once and insert the same identity value for all other inserted records!
can anyone help me what sortof view i shud create?
i am doing ths whole process thru a perl script so whatever sql tht needs to be done is done thru an sql file run from my perl script. mebbe asome sorta trigger will work tht automatically inserts the newest value of identityt generated into the alias field while insertion of records?
gosh i really need help here...so any ideas wud be gr8:)
thnx fr all the suggestions:)

-shuchi|||if this "alias" column is to have exactly the same values, then you don't really need it

just select it twice in any query -- select system_id
, system_name
, system_id as sys_alias
, sys_pro
, sys_values
from yourtable

rudy|||thanx a ton fr all the help...managed it:)

-shuchi

Inserting values and get the last ID recorded to use in another INSERT

I need to insert some values into a table and after that catch the ID inserted.

I set some input parameters in stored procedure and only one to get the @.id defined as output

SqlParameter paramIdPedido = new SqlParameter("@.APP_IDPEDIDO", SqlDbType.Int, 4);
paramIdPedido.Direction = ParameterDirection.Output;
cmd.Parameters.Add(paramIdPedido);

Do I have to run cmd.ExecuteNonQuery(); to record first what I need and after
run ExecuteReader: something like SqlDataReader dr = cmd.ExecuteReader();while (dr.Read()... to get the ID)

From stored procedure:

INSERT table(fields) VALUES(vars)
SELECT TOP 1 @.id = id FROM table ORDER BY id DESC

I must do all these steps or maybe is there anything less complex to do?

Thanks!

Hello Roberot,

Have a look at the following example:http://davidhayden.com/blog/dave/archive/2006/02/16/2803.aspx

Jeroen Molenaar.

Inserting values

Dear All,

In sql-server2000
In a table i am having a column of datatype varchar(8000).
While inserting the record through executenonquery, i am insert only
255 characters rest of the characters are getting trucated.

My question in how i will able to insert the row of that particular
column more than 255 characters

Thanx in advance.

Regardsfix the query.

i dunno what the query is or the command parameter info, so you'll just have to read on how to change the length of that sqldbtype.|||Dear Kragie,

thanx for your reply.

i am using command parameter info is command text and and directly using "Insert command".

Regards

Inserting values

Hello,
I have an table with fromdate and todate columns in experince table.
fromdate todate
01/10/2000 01/10/2001
10/10/2001 11/11/2003
12/11/2003 09/12/2005
i want to insert values
fromdate todate
10/10/2005 3/10/2006 as fromdate todate experinece dates.
i am using sql server as backend and asp as frontend.
before inserting i want is any experience available with this values
in the above three rows.
Please help me in this scenario
Regards,
Rama Kishore,
ramakishoreiic@.gmail.com
Hi
I'm confused
Can you explain more what are you trying to achivie?
IF NOT EXISTS ( SELECT * FROM Table WHERE ...)
--Inserting here
ELSE
something else
<ramakishoreiic@.gmail.com> wrote in message
news:1143029185.205342.166360@.i40g2000cwc.googlegr oups.com...
> Hello,
> I have an table with fromdate and todate columns in experince table.
> fromdate todate
> 01/10/2000 01/10/2001
> 10/10/2001 11/11/2003
> 12/11/2003 09/12/2005
>
> i want to insert values
> fromdate todate
> 10/10/2005 3/10/2006 as fromdate todate experinece dates.
> i am using sql server as backend and asp as frontend.
> before inserting i want is any experience available with this values
> in the above three rows.
> Please help me in this scenario
> Regards,
> Rama Kishore,
> ramakishoreiic@.gmail.com
>

Inserting values

Hello,
I have an table with fromdate and todate columns in experince table.
fromdate todate
01/10/2000 01/10/2001
10/10/2001 11/11/2003
12/11/2003 09/12/2005
i want to insert values
fromdate todate
10/10/2005 3/10/2006 as fromdate todate experinece dates.
i am using sql server as backend and asp as frontend.
before inserting i want is any experience available with this values
in the above three rows.
Please help me in this scenario
Regards,
Rama Kishore,
ramakishoreiic@.gmail.comHi
I'm confused
Can you explain more what are you trying to achivie?
IF NOT EXISTS ( SELECT * FROM Table WHERE ...)
--Inserting here
ELSE
something else
<ramakishoreiic@.gmail.com> wrote in message
news:1143029185.205342.166360@.i40g2000cwc.googlegroups.com...
> Hello,
> I have an table with fromdate and todate columns in experince table.
> fromdate todate
> 01/10/2000 01/10/2001
> 10/10/2001 11/11/2003
> 12/11/2003 09/12/2005
>
> i want to insert values
> fromdate todate
> 10/10/2005 3/10/2006 as fromdate todate experinece dates.
> i am using sql server as backend and asp as frontend.
> before inserting i want is any experience available with this values
> in the above three rows.
> Please help me in this scenario
> Regards,
> Rama Kishore,
> ramakishoreiic@.gmail.com
>

Inserting values

Hello,
I have an table with fromdate and todate columns in experince table.
fromdate todate
01/10/2000 01/10/2001
10/10/2001 11/11/2003
12/11/2003 09/12/2005
i want to insert values
fromdate todate
10/10/2005 3/10/2006 as fromdate todate experinece dates.
i am using sql server as backend and asp as frontend.
before inserting i want is any experience available with this values
in the above three rows.
Please help me in this scenario
Regards,
Rama Kishore,
ramakishoreiic@.gmail.comHi
I'm confused
Can you explain more what are you trying to achivie?
IF NOT EXISTS ( SELECT * FROM Table WHERE ...)
--Inserting here
ELSE
something else
<ramakishoreiic@.gmail.com> wrote in message
news:1143029185.205342.166360@.i40g2000cwc.googlegroups.com...
> Hello,
> I have an table with fromdate and todate columns in experince table.
> fromdate todate
> 01/10/2000 01/10/2001
> 10/10/2001 11/11/2003
> 12/11/2003 09/12/2005
>
> i want to insert values
> fromdate todate
> 10/10/2005 3/10/2006 as fromdate todate experinece dates.
> i am using sql server as backend and asp as frontend.
> before inserting i want is any experience available with this values
> in the above three rows.
> Please help me in this scenario
> Regards,
> Rama Kishore,
> ramakishoreiic@.gmail.com
>

Inserting unique values into a different tables if they don''t exists already.

Hi

I am trying to insert values into a table that doesn't exist there yet from another table, my problem is that because it is joined to the other table it keeps on selecting more values that i don't want.

Code Snippet

SET NOCOUNT ON

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

SELECT M.MemberID, '6', CASE M.MaritalStatusID WHEN 1 THEN '7'

WHEN 2 THEN '8'

WHEN 3 THEN '9'

WHEN 4 THEN '10'

END

FROM Members M

INNER JOIN _MemberProfileLookupValues ML

ON M.MemberID = ML.MemberID

WHERE M.Active = 1

AND OptionID <> 6

When i execute that code it returns all the values, let say OptionID = 3 is smoking already exists in the MemberProfileLookupValues table then it is going to select that persons memberID

I want to insert only members values that aren't already in the _MemberProfileLookupValues from the Members table (I think that it is because of the join statement that is in my code, but i don't know how i am going to select members that aren't in the table, because i have a few other queries that are very similar that are inserting different values, so ultimately

ONLY INSERT THE MemberID the values 6 and the statusID of X if it is not in the table already.

Any ideas / help will be greatly appreciated. Please help.

Kind Regards

Carel Greaves

The following query insert the new members who option id 6 is not exist in the MemberProfileLookupValues table,

Code Snippet

SET NOCOUNT ON

INSERT INTO _MemberProfileLookupValues (MemberID, OptionID, ValueID)

SELECT

M.MemberID

, '6'

, CASE M.MaritalStatusID WHEN 1 THEN '7'

WHEN 2 THEN '8'

WHEN 3 THEN '9'

WHEN 4 THEN '10'

END

FROM

Members M

Where

NOT EXISTS

(

Select 1 From _MemberProfileLookupValues ML

Where M.MemberID = ML.MemberID And OptionID = 6

)

And M.Active = 1

|||

Thanks a lot.

That is exactly what i was looking for.

Kind Regards

Carel Greaves

Friday, February 24, 2012

inserting to multiple fields using a button

I have multiple textboxes in a page. How do i make them insert their values to multiple fields on multiple tables using a button.

You can just execute some SqlCommands to insert data to different tables in the Click event of a button, for example:

protected void Button2_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(@."Data Source=labsh96223\iori2000;Integrated Security=SSPI;Database=tempdb"))
{
conn.Open();
string insertSql = @."Insert into myTbl_1 select @.id, @.name";
SqlCommand myCommand = new SqlCommand(insertSql, conn);
myCommand.Parameters.Add("@.id", SqlDbType.Int);
myCommand.Parameters.Add("@.name", SqlDbType.VarChar, 100);
myCommand.Parameters["@.id"].Value = Int32.Parse(TextBox1.Text);
myCommand.Parameters["@.name"].Value = TextBox2.Text;
int i = myCommand.ExecuteNonQuery();
myCommand.CommandText = @."Insert into myTbl_2 select @.id, @.Description";
myCommand.Parameters.Clear();
myCommand.Parameters.Add("@.id", SqlDbType.Int);
myCommand.Parameters.Add("@.Description", SqlDbType.VarChar, 1000);
myCommand.Parameters["@.id"].Value = Int32.Parse(TextBox3.Text);
myCommand.Parameters["@.name"].Value = TextBox4.Text;
i= myCommand.ExecuteNonQuery();
//execute other commands
}
}

inserting the current date and time into SQL Server database

I need an SQL string that inserts the current date into a database.

So far I have tried:

SQL = "INSERT INTO X (START_DATE) VALUES('" & Date.Now &"')"

mycomm =

New SqlCommand(sql, myconn)

mycomm.ExecuteNonQuery()

However, there is a problem with the SQL command. The problem is related to the date. Is there a way of programatically inserting the current date/time into the SQL database? Language used is VB.

GetDate() is a function in SQL Server that returns the current timestamp. So you can directly use that.

SQL = "INSERT INTO X (START_DATE) VALUES( GetDate())"