Showing posts with label insert. Show all posts
Showing posts with label insert. Show all posts

Monday, March 26, 2012

Prblem With Inserting Data With Identity

Greetings!

I Have A Little Problem...

Is It Possible To Make The Identity In My Table Reset?
I Have Used The Table Already To Make Insert Some Sample Data.. Now I Deleted Those Data Inserted.. The Problem Now Is That The Identity Goes On With Incrementing(obviously)...

For Example:

I Have 2 Columns And 3 Rows..
1st Col Is The Identity, 2nd Is Some Data...
The Rows Has Identities Which Are 1,2,3 Respectively..
Then I Manually Deleted The 3rd Row Which Has The ' 3 ' Value In The First Col... Now When I Inserted Data, The Value Becomes ' 4 ' In The First Col, Becuase Obvioulsy It Is An Identity Column..

My Question Is, Is It Possible To Still Have The ' 3 ' Value When I Insert A New Value?

Or Maybe Just Reset The Table To Start With The Last Identity In The Table... Just Like With My Example...
(some Scripts Maybe?)Follow the steps
1. Drop Identity Column from table and Save
2. Re Create Identity Column.

Hope fully your problem will be resolve.

Regards|||[QUOTE=vinci]Greetings!

I Have A Little Problem...

Is It Possible To Make The Identity In My Table Reset?
I Have Used The Table Already To Make Insert Some Sample Data.. Now I Deleted Those Data Inserted.. The Problem Now Is That The Identity Goes On With Incrementing(obviously)...

You can use this:

SET IDENTITY_INSERT TableName ON

and then attempt to insert with an identity number that has been deleted.

Tuesday, March 20, 2012

post from text box to SQL insert

Hello,

I'm trying to update a single field of a record and i want to do it using a standard multi line text box but I'm not sure how to write the c# command to process the sql update. I would also like the entry to be added into the database with line breaks.

Thanks for your help

There is nothing to ask..... you can do it using the same way u r updating the others.... you do not need any c# command.... its the query on which all this depends...

you can use query... : update <table name> set <feild name>= textbox1.text where <condition>....

and about multi lines.... you do not need to worry about line breaks..... the data would be stored in the database just as the way it is in the multiline textbox.... and would be fetched in the same manner...

and do tell me if its any worthy 4 u or not.

|||

Ok - In theroy I get what your saying but then I have VisStudio post out the code I need to make the text box and the supporting data source and I get all of this:

----------------

<asp:TextBox ID="txtNotes" runat="server"></asp:TextBox>
<asp:SqlDataSource ID="sqlUpdateNotes" runat="server" ConnectionString="<%$ ConnectionStrings:dbNetOps %>" DeleteCommand="DELETE FROM [MasterServerlist] WHERE [ID] = ?" InsertCommand="INSERT INTO [MasterServerlist] ([ID], [Notes]) VALUES (?, ?)" ProviderName="<%$ ConnectionStrings:dbNetOps.ProviderName %>" SelectCommand="SELECT [ID], [Notes] FROM [MasterServerlist] WHERE ([ID] = ?)" UpdateCommand="UPDATE [MasterServerlist] SET [Notes] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvServers" Name="ID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Notes" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
------------------

What I'm trying to do is :

1: display the contents of the notes field in the text box where the record matches the record selected in a gridview element

2: have the onchange event of the notes field then post back an update to the database and redisplay the new notes in the text field

I'm very new to ASP and appriciate your help.

Thank you

|||

I cannot find anything wrong in your code... could you please describe your problem in details...... or what kind of errors you are receiving(if any).....

And also you wanted to store all the data in the textbox to the database with the line breaks.... you should set the textmode attribute of textbox to multiline...

Monday, March 12, 2012

Possibly incorrect query result

/* Test table */
create table test (c1 char(1), c2 varchar(1));
insert into test values ('','');

/* Query */
select
c1,
len(c1) len_c1,
c2,
len(c2) len_c2
from test

The result of the len(c1) expression is 0. I would expect the correct result to be 1, since "c1" is a fixed-length character string type and the values are right-padded with spaces to fit the defined length, in this case 1.

I'm using SQL Server 2005.

Regards,
Ole Willy Tuv

LEN

Returns the number of characters, rather than the number of bytes, of the given string expression, excluding trailing blanks.

Change LEN to DATALENGTH and run this

select
c1,
datalength(c1) len_c1,
c2,
datalength(c2) len_c2
from test

select datalength(' '),len(' ')

Denis the SQL Menace

http://sqlservercode.blogspot.com/

Friday, March 9, 2012

Possible to Insert Records into ODBC Data Source from Stored Procedure?

I would like to insert records into a non MS-SQL database that I can connect
to with an ODBC data source.
This is possible? If so, can you give me an example of how to connect?
Thanks,
MikeYes, it is possible, and there are numerous ways of connecting to an ODBC
data source. If you are using C#, take a look at class OdbcConnection in the
System.Data.Odbc namespace --
http://msdn2.microsoft.com/en-us/library/at2sk77y.aspx.
Linchi
"Mike" wrote:
> I would like to insert records into a non MS-SQL database that I can connect
> to with an ODBC data source.
> This is possible? If so, can you give me an example of how to connect?
> Thanks,
> Mike
>
>

Possible to insert a page break?

I have a question regarding page break. Is there a way to add a page break
before a text box?
I know you can do this with tables, but I need to have the textbox which
contains the table title to start at the top of the page, instead of the
table itself. Thanks.
-JosephI'm not sure I understand the issue correctly, but did you try putting the
textbox inside a rectangle and add the page break on the rectangle?
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Joseph" <Joseph@.discussions.microsoft.com> wrote in message
news:72370566-0AAA-435C-B376-F16064A3D9EF@.microsoft.com...
> I have a question regarding page break. Is there a way to add a page
break
> before a text box?
> I know you can do this with tables, but I need to have the textbox which
> contains the table title to start at the top of the page, instead of the
> table itself. Thanks.
> -Joseph|||Rectangle solves my needs. Thanks Robert.
Joseph
"Robert Bruckner [MSFT]" wrote:
> I'm not sure I understand the issue correctly, but did you try putting the
> textbox inside a rectangle and add the page break on the rectangle?
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Joseph" <Joseph@.discussions.microsoft.com> wrote in message
> news:72370566-0AAA-435C-B376-F16064A3D9EF@.microsoft.com...
> > I have a question regarding page break. Is there a way to add a page
> break
> > before a text box?
> >
> > I know you can do this with tables, but I need to have the textbox which
> > contains the table title to start at the top of the page, instead of the
> > table itself. Thanks.
> >
> > -Joseph
>
>