Inserting A Select With An Additional Static Field
Jul 20, 2005
I have a stored procedure where I want to select all fields matching
the query into another table. In addition, I want to add a common
groupID to each of the records that are being inserted into the second
table.
I can get the results that I want by using a temporary table but need
to know if there is a way to do it directly..
below is the code that uses the temporary table..
CREATE TABLE #tempStore_DeliveryAddress (
[AddressId] [int] IDENTITY (1, 1) NOT NULL ,
[UserId] [int] NOT NULL ,
[Title] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[FirstName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[SpouseName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[MiddleName] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[SpouseMiddleName] [varchar] (10) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[LastName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[SpouseLastName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,
[Suffix] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[SpouseSuffix] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[Company] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[Address1] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[Address2] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[Address3] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[City] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[State] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[PostalCode] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[Country] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[ForeignFlag] [int] NULL CONSTRAINT
[DF_Store_DeliveryAddress_ForeignFlag] DEFAULT (0),
[Email] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[Greeting] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[FullName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[ShortName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[OptOut] [int] NULL CONSTRAINT [DF_Store_DeliveryAddress_OptOut]
DEFAULT (0),
[Modified] [datetime] NULL CONSTRAINT
[DF_Store_DeliveryAddress_Modified] DEFAULT (getdate()),
[Modifer] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
CONSTRAINT [DF_Store_DeliveryAddress_Modifer] DEFAULT ('DBA'),
[Created] [datetime] NULL CONSTRAINT
[DF_Store_DeliveryAddress_Created] DEFAULT (getdate()),
[Creator] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
CONSTRAINT [DF_Store_DeliveryAddress_Creator] DEFAULT ('DBA'),
[MailListID] [int] NULL ,
CONSTRAINT [PK_Store_DeliveryAddress] PRIMARY KEY CLUSTERED
(
[AddressId]
) ON [PRIMARY]
) ON [PRIMARY]
INSERT INTO #tempStore_DeliveryAddress([UserId], [Title], [FirstName],
[SpouseName], [MiddleName], [SpouseMiddleName], [LastName],
[SpouseLastName], [Suffix], [SpouseSuffix], [Company], [Address1],
[Address2], [Address3], [City], [State], [PostalCode], [Country],
[ForeignFlag], [Email], [Greeting], [FullName], [ShortName], [OptOut],
[Modified], [Modifer], [Created], [Creator])
(SELECT [UserId], [Title], [FirstName], [SpouseName], [MiddleName],
[SpouseMiddleName], [LastName], [SpouseLastName], [Suffix],
[SpouseSuffix], [Company], [Address1], [Address2], [Address3], [City],
[State], [PostalCode], [Country], [ForeignFlag], [Email], [Greeting],
[FullName], [ShortName], [OptOut], [Modified], [Modifer], [Created],
[Creator]
FROM [ntmportal].[dbo].[Store_AddressBook]
WHERE [AddressID] in (Select AddressID From Store_AddressesForGroup
where AddressGroupID = 322))
UPDATE #tempStore_DeliveryAddress set MailLISTID = 422
INSERT INTO Store_DeliveryAddress([UserId], [Title], [FirstName],
[SpouseName], [MiddleName], [SpouseMiddleName], [LastName],
[SpouseLastName], [Suffix], [SpouseSuffix], [Company], [Address1],
[Address2], [Address3], [City], [State], [PostalCode], [Country],
[ForeignFlag], [Email], [Greeting], [FullName], [ShortName], [OptOut],
[Modified], [Modifer], [Created], [Creator], [MailListID])
(Select [UserId], [Title], [FirstName], [SpouseName], [MiddleName],
[SpouseMiddleName], [LastName], [SpouseLastName], [Suffix],
[SpouseSuffix], [Company], [Address1], [Address2], [Address3], [City],
[State], [PostalCode], [Country], [ForeignFlag], [Email], [Greeting],
[FullName], [ShortName], [OptOut], [Modified], [Modifer], [Created],
[Creator], [MailListID]
FROM #tempStore_DeliveryAddress)
View 2 Replies
ADVERTISEMENT
Apr 11, 2006
I have the following fields in table A:
GL_ID|GL_Name_VC| Amount |Period_TI|Year_SI|
===================================================
1000| Sales_HW| -20,000.00 | 01 | 2005
===================================================
1000| Sales_SW| -10,000.00 | 01 | 2005
===================================================
1001| Cost_HW | 5,000.00 | 01 | 2005
===================================================
1001| Cost_SW | 5,000.00 | 01 | 2005
the fields above have the following datatype:
Fields | Datatype
===================================
GL_ID | Integer
GL_Name_VC | Variable Character
Amount | Integer
Period_TI | TinyInteger
Year_SI | SmallInteger
The above database is running on Microsoft SQL Server 2000 and i would like to query
for a report that looks something as below:
Sales Category | Sales | Cost | Profit
=================================================
HW |-20,000.00 |5,000.00| -15,000.00
SW |-10,000.00 |5,000.00| -5,000.00
=================================================
Total |-30,000.00 |10,000.00|-20,000.00
The above report have 4 columns, with last column being a calculated field (Sales-Cost)
Guys, hope someone out there can help me with the sql command for the above report?
View 2 Replies
View Related
Feb 12, 2007
I've got a CLR stored proc I'm trying to deploy to SQL2005, when I try to debug it I get the error message:
Method, property or field 'usp_Evaluate_eTranscript' of class 'ACS_eTranscripts.StoredProcedures' in assembly 'ACS_eTranscripts' is not static.
The class & procedure are declared:
Partial Public Class StoredProcedures Private Structure CalcGPA Friend intGrdTot As Integer Friend intCrsKnt As Integer End Structure <Microsoft.SqlServer.Server.SqlProcedure()> _ Public Sub usp_Evaluate_eTranscript(ByVal SSN As String)
When I change the sub's declaration to:
Static Sub usp_Evaluate_eTranscript(ByVal SSN As String)
I get an error message that:
Methods cannot be static.
So, is this a Catch 22 or what am I missing?
Any help would be greatly appreciated as this is a major project and I am woefully behind because of emergency surgery.
View 8 Replies
View Related
Oct 17, 2006
Let's say I have a simple query to return the results of my "Status" table. The query reads as follows:
Code:
Select statusID, statusName
From Status
Here is the result set that I am returned:
Code:
22 Associate Member
23 Is Not Paying
24 Exempt
25 Fair Share
26 Member
29 Retiree
30 Staff
32 Fair Share - Self Pay
34 Member - Self Pay
Now, I am using this query for reporting purposes and would like to inject some additional sql that will append one additional row to my result set -- this is what I am calling the 'static' row in the thread title.
In other words, without modifying my database I would like to return the above set of data but with one additional row that has an arbitrary ID with the name "Unknown" or something similar.
again, I want to avoid adding an "Unknown" field directly to my database -- is their any way to "hard code" the selection of this row in my sequal?
Thanks,
Zoop
View 1 Replies
View Related
Feb 22, 2006
I'm using Delphi 2006 to create a DLL which will be integrated into SQL 2005. It's been a long road and I've made a lot of headway, however I am currently having the following problem creating the stored procedure:
My dll name is 'Crystal_Reports_Test_01'
In the DLL, my class is named 'Class01'.
In the DLL, my procedure is named 'TestMe'
I've managed to integrate the DLL into SQL using the following statement:
CREATE ASSEMBLY TEST_ERIC_01
AUTHORIZATION dbo
FROM 'c:mssqlassembliescrystalreports.dll'
WITH PERMISSION_SET = UNSAFE
I am attempting to create the stored procedure which points to the 'TestMe' method inside of the DLL. FYI: 'CrystalReports' is the namespace above my class that I had to add in order to get it to locate the class. The following code is used to create the stored procedure:
create procedure dbo.Crystal_Reports_Test_01(
@Parm1 nvarchar(255)
)
as external name TEST_ERIC_01.[CrystalReports.Class01].TestMe
But I get the following error:
Msg 6573, Level 16, State 1, Procedure Crystal_Reports_Test_01, Line 1Method, property or field 'TestMe' of class 'CrystalReports.Class01' in assembly 'CrystalReports' is not static.
I'm not sure what this means exactly. I think it means the method (the procedure) is not using Static method binding but should be. I have no idea what this really means or how to accomplish this in the DLL - or if I'm even going about this in the right way.
Any help would be appreciated ! I'll post the Delphi code (DLL) below.
Thanks,
Eric Gooden
library CrystalReports;uses System.Reflection, System.Runtime.InteropServices;...................type Class01 = class public procedure TestMe([MarshalAs(UnmanagedType.LPWStr)] var sVarString: wideString); export; end;procedure Class01.TestMe([MarshalAs(UnmanagedType.LPWStr)] var sVarString: wideString); export;begin sVarString:= 'Lets change the value and see if the stored proc. gets the change.';end;end.
View 4 Replies
View Related
Jan 26, 2008
I'm trying to populate a table of pending emails. The problem is I need
to populate the email field using a select statement but the message
field with static text. Can this be done or is another approach more
prudent? What I have is below but is kicking errors:DECLARE @msg varchar(300) SET @msg = 'New users have applied for accounts. Please review their information.'IF @Type='CreateUserApply' INSERT INTO cdds_Email (Address,Message)VALUES (SELECT M.EmailFROMdbo.aspnet_Membership MINNER JOINdbo.aspnet_UsersInRoles UINNER JOINdbo.aspnet_Roles RON U.RoleId = R.RoleIdON U.UserId = M.UserIdWHERER.RoleName = 'Manager',@msg)
View 3 Replies
View Related
Jul 31, 2007
an example for the pb
1)First i have created a dynamic cursor :
DECLARE authors_cursor CURSOR DYNAMIC
FOR Select DISTINCT LOCATION_EN AS "0Location" from am_location WHERE LOCATION_ID = 7
OPEN authors_cursor
FETCH first FROM authors_cursor
2)The result for this cursor is for expamle 'USA'.
3) If now i do an update on that location with a new value 'USA1'
update am_location set location_en = 'USA1' WHERE LOCATION_ID = 7
4)now if i fetch the cursor , i''ll get the old value (USA) not (USA1).
If i remove DISTINCT from the cursor declaration , the process works fine .
View 10 Replies
View Related
Jul 31, 2007
An example for my pb
1) Created a dynamic cursor :
DECLARE cursor_teste CURSOR DYNAMIC
FOR Select DISTINCT name from table WHERE ID = 1
OPEN cursor_teste
FETCH first FROM cursor_teste
2)The result for this cursor is for example 'teste'.
3) If now i do an update on that name with a new value 'teste1'
than if i fetch the cursor , i''ll get the old value (teste) .
any idea how to make a select distinct result in a dynamic Cursor?
View 7 Replies
View Related
Feb 29, 2008
I am trying to get a function I created in VB 5 for Access and Excel to work in SQL 2005. I was able to update the old VB code to work in VB 2005. I compiled and made a .dll, and I was able to register the new Assembly in SQL Server. When I try to create the Function, I get an error:
CREATE FUNCTION dbo.Temperature(@FluidName char, @InpCode Char, @Units Char, @Prop1 varchar, @Prop2 varChar)
RETURNS VarChar
AS EXTERNAL NAME FluidProps.[FluidProps.FluidProperties.Fluids].Temperature
Error returned:
Msg 6573, Level 16, State 1, Procedure Temperature, Line 21
Method, property or field 'Temperature' of class 'FluidProps.FluidProperties.Fluids' in assembly 'FluidProps' is not static.
Here is the code (part of it) in the VB class:
Header:
Imports Microsoft.SqlServer.Server
Imports System.Data.SqlClient
Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Security.Permissions
Namespace FluidProperties
'Option Strict Off
'Option Explicit On
Public Partial Class Fluids
Function:
Function Temperature(ByRef FluidName As Object, ByRef InpCode As Object, ByRef Units As Object, ByRef Prop1 As Object, Optional ByRef Prop2 As Object = Nothing) As Object
Call CalcProp(FluidName, InpCode, Units, Prop1, Prop2)
Temperature = ConvertUnits("-T", Units, T, 0)
End Function
If I change the Function Temperature to Static, I get an error that functions cannot be Static. Its been a long time since I created the code and am having a hard time in my older age of getting the cobwebs out to make it work.
I have no problem getting the function to work if I call it from a VB form....so what do I need to do to get it to work on data in my SQL server?
Thanks
Buck
View 20 Replies
View Related
Feb 7, 2007
I keep getting the following error message but I don't see what's wrong with my code
Server Error in '/Admin' Application.
Arithmetic overflow error converting expression to data type datetime.The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Arithmetic overflow error converting expression to data type datetime.The statement has been terminated.Source Error:
Line 147:cmdSql.Parameters.Add("@event_active","1")
Line 148:
Line 149:cmdSql.ExecuteNonQuery()
Line 150:
Line 151:pnlForm.Visible = FalseSource File: c:hostingwebhost4lifememberNYACOAadmincalendar.aspx Line: 149 Stack Trace:
[SqlException (0x80131904): Arithmetic overflow error converting expression to data type datetime.
The statement has been terminated.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857466
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735078
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +149
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +415
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
ASP.calendar_aspx.SubmitForm(Object s, EventArgs E) in c:hostingwebhost4lifememberNYACOAadmincalendar.aspx:149
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
1 <%@ Register TagPrefix="cc1" Namespace="ManyMonkeys.Web.HtmlEditorLibrary.Controls" Assembly="HtmlEditorLibrary" %>
2 <%@ Page Language="VB" masterpagefile="nyacoaadmin.master" debug="true" %>
3 <%@ mastertype virtualpath="nyacoaadmin.master" %>
4 <%@ import Namespace="System" %>
5 <%@ import Namespace="System.Data" %>
6 <%@ import Namespace="System.Data.SqlClient" %>
7 <script runat="server">
8
9 Dim Connection As SqlConnection
10 Dim Sql As String
11 Dim cmdSql As SqlCommand
12 Dim dtr As SqlDataReader
13
14 Sub Page_Load
15
16 Connection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
17 Connection.Open()
18
19 If Not isPostback then
20
21 Sql = "SELECT chapter_id, chapter_name FROM chapter ORDER BY chapter_id"
22 cmdSql = New SqlCommand (Sql, Connection)
23 dtr = cmdSql.ExecuteReader()
24
25 ddlChapter.DataSource = dtr
26 ddlChapter.DataTextField = "chapter_name"
27 ddlChapter.DataValueField = "chapter_name"
28 ddlChapter.DataBind()
29
30 dtr.Close
31
32 ddlChapter.Items.Insert(0, New ListItem(" ", ""))
33
34 Call ShowList()
35
36 End If
37
38 End Sub
39
40 Sub Page_Unload
41
42 'Connection.Close()
43
44 End Sub
45
46 Sub ShowList()
47
48 Sql = "SELECT event_id, event_name, event_date, chapter_name FROM event WHERE event_active = '1' ORDER BY event_id"
49 cmdSql = New SqlCommand(sql, Connection)
50 dtr = cmdSql.ExecuteReader()
51
52 dgrdList.DataSource = dtr
53 dgrdList.DataBind()
54 dtr.Close()
55
56 pnlList.Visible = True
57
58 End Sub
59
60 Sub dgrdList_ItemCommand(s As Object, E As DataGridCommandEventArgs)
61
62 If e.CommandName = "edit" then
63 Call EditForm(dgrdList.DataKeys(e.Item.ItemIndex))
64 Else If e.CommandName = "delete" then
65 Call ConfirmDelete(dgrdList.DataKeys(e.Item.ItemIndex))
66 End If
67
68 End Sub
69
70 Sub ConfirmDelete(idVal As Integer)
71
72 pnlList.Visible = False
73 pnlConfirmDelete.Visible = True
74
75 sql = "SELECT event_name FROM event WHERE event_id = " & idVal
76 cmdSql = New SqlCommand(sql, connection)
77 litDelete.Text = cmdSql.ExecuteScalar()
78
79 ViewState("idVal") = idVal
80
81 End Sub
82
83 Sub DeleteForm (s As Object, E As Eventargs)
84
85 sql = "UPDATE event SET event_active = '0' WHERE event_id = " & ViewState("idVal")
86 cmdSql = New SqlCommand(sql, connection)
87 cmdSql.ExecuteNonQuery()
88
89 pnlList.Visible = True
90 pnlConfirmDelete.Visible = False
91
92 Call ShowList()
93
94 End Sub
95
96 Sub ShowCalendar(s As Object, E As ImageClickEventargs)
97
98 pnlEventDate.Visible = True
99
100 End Sub
101
102 Sub UpdateDate (s As Object, E As Eventargs)
103
104 pnlEventDate.Visible = False
105 txtEventDate.text=eventCalendar.SelectedDate.ToShortDateString()
106
107 End Sub
108
109 Sub SubmitForm (s As Object, E As Eventargs)
110
111 If ViewState("submitType") = "edit" then
112 sql = "UPDATE event SET event_name=@event_name, event_date=@event_date, chapter_name=@chapter_name, event_description=@event_description, event_last_updated_by=@event_last_updated_by, event_active=@event_active WHERE event_id = " & ViewState("idVal")
113 Else
114 sql = "INSERT INTO event (event_name, event_date, chapter_name, event_description, event_added_by, event_last_updated_by, event_active) VALUES (@event_name, @event_date, @chapter_name, @event_description, @event_added_by, @event_last_updated_by, @event_active)"
115 End If
116
117 cmdSql = New SqlCommand(sql, Connection)
118
119 If Len(txtEventName.Text) = 0 then
120 cmdSql.Parameters.Add("@event_name",DbNull.Value)
121 Else
122 cmdSql.Parameters.Add("@event_name",txtEventName.Text)
123 End If
124
125 If Len(txtEventDate.Text) = 0 then
126 cmdSql.Parameters.Add("@event_date",DbNull.Value)
127 Else
128 cmdSql.Parameters.Add("@event_date",txtEventDate.Text & " " & ddlEventHour.SelectedValue & ":" & ddlEventMinute.SelectedValue & " " & ddlEventAMPM.SelectedValue)
129 End If
130
131 If Len(ddlChapter.SelectedValue) = 0 then
132 cmdSql.Parameters.Add("@chapter_name",DbNull.Value)
133 Else
134 cmdSql.Parameters.Add("@chapter_name",ddlChapter.SelectedValue)
135 End If
136
137 If Len(txtEventDescription.Text) = 0 then
138 cmdSql.Parameters.Add("@event_description",DbNull.Value)
139 Else
140 cmdSql.Parameters.Add("@event_description",txtEventDescription.Text)
141 End If
142
143 cmdSql.Parameters.Add("@event_added_by",session("admin_username"))
144
145 cmdSql.Parameters.Add("@event_last_updated_by",session("admin_username"))
146
147 cmdSql.Parameters.Add("@event_active","1")
148
149 cmdSql.ExecuteNonQuery()
150
151 pnlForm.Visible = False
152 pnlList.Visible = True
153
154 Call ShowList()
155
156 End Sub
157
158 Sub AddForm(s As Object, E As Eventargs)
159
160 pnlForm.Visible = True
161 pnlList.Visible = False
162
163 txtEventName.Text = ""
164 txtEventDate.Text = ""
165 ddlChapter.ClearSelection()
166 txtEventDescription.Text = ""
167
168 ViewState("submitType") = "add"
169
170 End Sub
171
172 Sub EditForm (idVal As Integer)
173
174 pnlList.Visible = False
175 pnlForm.Visible = True
176
177 sql = "SELECT * FROM event WHERE event_id = " & idVal
178 cmdSql = New SqlCommand(sql, connection)
179 dtr = cmdSql.ExecuteReader()
180
181 If dtr.Read() then
182
183 txtEventName.Text = dtr("event_name") & ""
184 txtEventDate.Text = dtr("event_date") & ""
185 txtEventDescription.Text = dtr("event_description") & ""
186 ddlChapter.ClearSelection()
187 Try
188 ddlChapter.Items.FindByValue(dtr("chapter_name")).Selected = True
189 Catch Ex As Exception
190 End Try
191
192 End If
193
194 dtr.Close()
195
196 ViewState("submitType") = "edit"
197 ViewState("idVal") = idVal
198
199 End Sub
200
201 Sub DeleteCancel (s As Object, E As Eventargs)
202
203 pnlConfirmDelete.Visible = False
204 pnlList.Visible = True
205
206 End Sub
207
208 </script>
209
210 <asp:Content contentplaceholderid="cplhMainContent" runat="server">
211
212 <asp:Panel runat="server" id="pnlList" Visible="False">
213
214 <asp:DataGrid runat="server" id="dgrdList" AutoGenerateColumns="False" CellPadding="3" CellSpacing="0" width="550" Border="0" DataKeyField="event_id" onItemCommand="dgrdList_ItemCommand">
215 <HeaderStyle BackColor="#CDAD00" Font-Names="Tahoma,Arial,Helvetica,sans-serif" Font-Bold="true" Font-Size="10pt" HorizontalAlign="center" ForeColor="white" />
216 <ItemStyle BackColor="white" Font-Names="Tahoma,Arial,Helvetica,sans-serif" Font-Size="10pt" ForeColor="black" VerticalAlign="top" />
217 <AlternatingItemStyle BackColor="#dcdcdc" Font-Names="Tahoma,Arial,Helvetica,sans-serif" Font-Size="10pt" ForeColor="black" VerticalAlign="top" />
218 <Columns>
219 <asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="edit" />
220 <asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="delete" />
221 <asp:BoundColumn DataField="event_name" HeaderText="Event Name" />
222 <asp:BoundColumn DataField="event_date" HeaderText="Date" />
223 <asp:BoundColumn DataField="chapter_name" HeaderText="Sponsoring Chapter" />
224 </Columns>
225 </asp:DataGrid>
226
227 <asp:Button runat="server" Text="Add New Event" onClick="AddForm"></asp:Button>
228
229 </asp:Panel>
230
231 <asp:Panel runat="server" id="pnlForm" Visible="False">
232
233 Name of Event: <asp:TextBox id="txtEventName" runat="server"></asp:TextBox>
234 <br />Chapter: <asp:DropDownList id="ddlChapter" runat="server" AutoPostBack="False" />
235 <br />Date: <asp:TextBox id="txtEventDate" runat="server" ReadOnly="true" BackColor="Gray"></asp:TextBox> <asp:ImageButton id="CalButton" runat="server" OnClick="ShowCalendar" ImageUrl="images/cal.gif" />
236 <br /><asp:Panel runat="server" id="pnlEventDate" Visible="False">
237 <asp:Calendar id="eventCalendar" runat="server" FirstDayOfWeek="Sunday" Font-Names="Tahoma" Font-Size="8pt" OnSelectionChanged="UpdateDate">
238 <SelectedDayStyle BackColor="#EC9900" Font-Bold="True" />
239 <TodayDayStyle BackColor="#FFC0C0" />
240 <SelectorStyle Font-Names="Tahoma" Font-Size="8pt" />
241 <DayStyle Font-Names="Tahoma" Font-Size="8pt" />
242 <WeekendDayStyle BackColor="#E0E0E0" />
243 <OtherMonthDayStyle ForeColor="Silver" />
244 <DayHeaderStyle BackColor="#334B79" Font-Names="Tahoma" Font-Size="8pt" ForeColor="White" />
245 <TitleStyle BackColor="#CCCCFF" Font-Bold="True" Font-Names="Tahoma" Font-Size="10pt" />
246 </asp:Calendar>
247 <br />
248 </asp:Panel>
249 Time: <asp:DropDownList ID="ddlEventHour" runat="server" >
250 <asp:ListItem Text="12" Value="12" Selected="true"/>
251 <asp:ListItem Text="1" Value="1" />
252 <asp:ListItem Text="2" Value="2" />
253 <asp:ListItem Text="3" Value="3" />
254 <asp:ListItem Text="4" Value="4" />
255 <asp:ListItem Text="5" Value="5" />
256 <asp:ListItem Text="6" Value="6" />
257 <asp:ListItem Text="7" Value="7" />
258 <asp:ListItem Text="8" Value="8" />
259 <asp:ListItem Text="9" Value="9" />
260 <asp:ListItem Text="10" Value="10" />
261 <asp:ListItem Text="11" Value="11" />
262 </asp:DropDownList>
263 :
264 <asp:DropDownList ID="ddlEventMinute" runat="server">
265 <asp:ListItem Text="00" Value="00" Selected="true" />
266 <asp:ListItem Text="15" Value="15" />
267 <asp:ListItem Text="30" Value="30" />
268 <asp:ListItem Text="45" Value="45" />
269 </asp:DropDownList>
270 <asp:DropDownList ID="ddlEventAMPM" runat="server">
271 <asp:ListItem Text="AM" Value="AM" />
272 <asp:ListItem Text="PM" Value="PM" Selected="true" />
273 </asp:DropDownList>
274 <br /><br />
275 Content:
276 <br /><cc1:HtmlEditor id="txtEventDescription" runat="server" Height="300px" Width="575px"></cc1:HtmlEditor>
277 <br /><br />
278 <asp:Button onclick="SubmitForm" runat="server" Text="Submit"></asp:Button>
279
280 </asp:Panel>
281
282 <asp:Panel runat="server" id="pnlConfirmDelete" Visible="False">
283
284 Are you sure you wish to delete <asp:Literal runat="server" id="litDelete"></asp:Literal>?
285 <br /><br />
286 <asp:Button runat="server" Text="Yes - DELETE" onClick="DeleteForm"></asp:Button> <asp:Button runat="server" Text="No - GO BACK" onClick="DeleteCancel"></asp:Button>
287
288 </asp:Panel>
289
290 </asp:Content>
View 4 Replies
View Related
Jul 29, 2007
Hi All,I am trying to insert symbols in a field of a table. I am using the datatype nvarchar for the field.However when i tried to insert a statement with the symbol pi, it comes out as following:(A) 100? cm2 (B) 140? cm2 (C) 200? cm2All the pi symbol are converted to ?.Can ne 1 tell me how i can store such strings in the field.Thanks
View 1 Replies
View Related
Apr 24, 2002
how do i add a new field and insert a value into it?
I'm importing data from another table into a new one, but my source table has a char field and the target filed is (int) can I add a new field to the source file and add a value to it? and how?
I have in my source table a field call companyName that contains text and the target table has a companyId which is an INT.
If I create a field call companyId and add a value of '1' depending on the value of CompanyName...
This is what i want ot do
if CompanyName = LA then insert 1 into new filed companyID
How can I do that? I have to do this for 100 or more tables. Can I write a script that will do that for me?
does it make sence?
View 2 Replies
View Related
Apr 21, 2008
Hello,
I'm trying to insert a string expression into a varbinary field. I've tried it several ways, but the data does not seem to get inserted.
I map DT_STR field ("T") with varbinary field in destination table and the package executes properly, but when I see the data that it has been loaded I only see empty values (0x).
I have also tried other approaches, like converting to DT_BYTES during SSIS flow, but I always get the same result.
Any idea of how to achieve this?
View 1 Replies
View Related
Nov 15, 2006
I have a table with the following schema:
CREATE TABLE [itis].[wrk_taxon_authors] (
[wb_taxon_author_id] [int] NOT NULL ,
[taxon_author_id] [int] IDENTITY (1, 1) NOT NULL ,
[taxon_author] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[kingdom_id] [smallint] NOT NULL
) ON [PRIMARY]
GO
I am trying to insert the following data (as you can see fields are seperated with the | ):
19||Flores-Villela and Sánchez-H., 2003|5|
20||Wiegmann, 1828|5|
16|17482|Gray, 1838|5|
17|9823|(Wiegmann, 1828)|5|
I get the following error:Server: Msg 4869, Level 16, State 1, Line 1
Bulk Insert failed. Unexpected NULL value in data file row 1, column 2. Destination column (taxon_author_id) is defined NOT NULL.
Server: Msg 4869, Level 16, State 1, Line 1
Bulk Insert failed. Unexpected NULL value in data file row 2, column 2. Destination column (taxon_author_id) is defined NOT NULL.
Since I have defined column 2 as an identity column, I don't understand why SQL Query analyzer is upset when I do not have a value in that field. To me, I would think it would auto-insert an integer (starting at seed 1 and incrementing by 1), but it doesn't. Could someone tell me what I'm doing wrong?
View 7 Replies
View Related
Jul 30, 2007
Hi All,
I am trying to insert symbols in a field of a table.
I am using the datatype nvarchar for the field.
However when i tried to insert a statement with the symbol pi, it comes out as following:
(A) 100? cm2 (B) 140? cm2 (C) 200? cm2
All the pi symbol are converted to ?.
Can ne 1 tell me how i can store such strings in the field.
Thanks
View 3 Replies
View Related
Feb 21, 2007
I am trying to insert 1000000.00 into my sql table from a webpage. I as long as the amount is 999.99 or less it works fine, once higher then that amount it gives me an error.
Below is the code I am using to do the insert, it gets the error on the insert and the update both:
I am getting the error on the price inserting the FormatCurrency(txtprice.Text)
SelectStatement = "Insert crewchief (crewchief, price, car_num) Select '" & txtcrewchief.Text & "', " & FormatCurrency(txtprice.Text) & ", '" & txtcarnum.Text & "'"
Adapter.SelectCommand = New SqlClient.SqlCommand(SelectStatement, myConnection)
MyCommandBuilder = New SqlClient.SqlCommandBuilder(Adapter)
Adapter.Fill(MatcherDS, "temp")
Any ideas on why?
Thank you
View 2 Replies
View Related
Aug 17, 2007
I have a datetime field in a database which I am programmatically inserting values into. The field can be null or not null. However, I am having problems inserting NULL as part of my SQLCommand.
The value is pulled from a text box (linked to a calendar extender) and when I select a value it is being inserted fine. If I just leave the box blank though, I want the field to be set to NULL. I have tried adding in ,DBNULL.Value, as part of my VALUES(…) string, but this throws an exception. I Have tried just inserting ‘’ but that also throws an exception (“The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value�), so I don’t know how I can insert this value when the field is blank?
Can anyone shed some light please? Thanks
View 2 Replies
View Related
Apr 6, 2008
I have a field in a db table which is like a chat history.I need to update the field with a user's input (put into a multiline text box) and append that to the beginning of the field.The problem is that I want to maintain line breaks when I retrieve the field into a multiline textbox (aka textarea) and can't figure it out.I've searched around and have seen lots of solutions for converting line breaks into <br> tags, but those people are trying to output to a label.I'm using an update command in my SqlDataSource like this: UpdateCommand="UPDATE [account] SET [history] = @history + history WHERE [id] = 1"With a parameter declaration like this: <UpdateParameters> <asp:ControlParameter Name="history" ControlID="TextBox1" PropertyName="Text" /> </UpdateParameters>If I try to concatenate in a or CHR(10), the characters are literally inserted. Like this for example (this is the last variation I tried).... UpdateCommand="UPDATE [account] SET [history] = @history + CHR(10) + history WHERE [id] = 1"How do I store a CrLf programatically?
View 6 Replies
View Related
Jun 2, 2008
Hello Everyone,
I have looked and looked for any information on how to insert data from a db into a text field using a stored procedure. If anyone has any helpful links or suggestions, my sanity would greatly appreciate the help.
Thank you
View 1 Replies
View Related
Feb 26, 2006
Hello,
I was wondering if someone could give me some insight to why i may be having this SQL 05 problem. I have setup a series of cells using say vchar(max). However when i go into add data in the table if I enter anything on of the word i.e. insert(Hello my name is) This red circle with an exclamation mark ( ! ) pops up and then if i continue to do another row it wont let me continue.
The message i get is
Error Source: .netSql Client Data provider
Error message: String or binary data would be truncated.
The statement has been terminated,
Then it says to fix this or press escape, i have never seen this before can help me out as I have no idea why this is happening.
Any help much appreciated.
View 1 Replies
View Related
Mar 22, 2006
HiI am trying to insert value retrieved from Now() into a datetime field in my MSDE database, but I am getting the following error, and I have no idea what is going wrong.Arithmetic overflow error converting expression to data type datetime.The statement has been terminated.Here is the code I am using:Dim user As String = MyContext.User.Identity.Name.ToString
Dim TimeDate As DateTime = Now()
Dim status As String = "Pending"
With SqlOrders.InsertParameters
.Item("UserName").DefaultValue = user
.Item("OrderDate").DefaultValue = TimeDate
.Item("Status").DefaultValue = status
End With
SqlOrders.Insert()The date is being returned in this format 23/03/2006 02:01:52, which is the same format as it should appear in the database. could anyone please tell me where I am going wrong?
View 2 Replies
View Related
May 9, 2000
Can some one please tell me how to update a field in a table with multiple
values for each of the values in the other fields?
Thanks in advance.
View 1 Replies
View Related
Feb 15, 2006
can we insert multiple values into the same field. as we do for the mailing list. that is can we use commas to enter multiple values into the same field
View 10 Replies
View Related
Mar 14, 2008
I need to insert rows into a table which contains a smallint field
for time. The times are stored in that colum as integers (898,
11345, 1259, etc.) How can I enter a time like 9:15 AM into this field? I know how to display integer data in hh:mm format but I'm stumped on how I can do the reverse.
Thanks for any help offered.
View 12 Replies
View Related
Nov 12, 2007
Can a bitmap be added to a Varbinary field using the INSERT statement. If not what other method can I use to add a photo image (bmp or gif) to my Sql database?
View 4 Replies
View Related
Jun 5, 2007
what i understand if if the data field is integer or money, not string, then i need to do a convert(datatype, value) in the insert but how come its still not working INSERT INTO [Product] ([Title], [Description], [Processor], [Motherboard], [Chipset], [RAM], [HDD], [OpticalDrive], [Graphics], [Sound], [Speakers], [LCD], [Keyboard], [Mouse], [Chassis], [PSU], [Price]) VALUES (@Title, @Description, @Processor, @Motherboard, @Chipset, @RAM, @HDD, @OpticalDrive, @Graphics, @Sound, @Speakers, @LCD, @Keyboard, @Mouse, @Chassis, @PSU, convert(smallmoney, @Price))
View 1 Replies
View Related
Jun 30, 2007
See my code below... it nicely insert in database data...
but I wish: if user of program in field "txtPozicija" try insert in
database same data detail like is in "Pozicija" field in database that
he be stopped and informed by message: you can not insert TWO SAME data
in the "Pozicija" table.
any advice here?
I AM TRY SOLVE THIS LIKE BELOW, NO ERROR BUT NOT WORK
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class adminpanel_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblHR.Text = txtPozicija.Text;
lblEN.Text = txtLinkZaViseoMjestu.Text;
lblIT.Text = ddRegija.Text;
}
// On dropbox in the html added OnDataBound="MyDataBound" Occurs after the server control binds to a data source.
protected void myDataBound(Object sender, EventArgs e)
{
ddRegija.Items.Insert(0, "--- Selektiraj ---");
}
void SaveDataDB()
{
string ConnStr = ConfigurationManager.ConnectionStrings["croestate_dbConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(ConnStr);
try
{
Conn.Open();
String sqlQuery = "INSERT INTO PozicijaObjekta VALUES(@Pozicija, @LinkzaViseoMjestu, @Regija)";
SqlCommand cmd = new SqlCommand(sqlQuery, Conn);
cmd.Parameters.AddWithValue("@Pozicija", txtPozicija.Text);
cmd.Parameters.AddWithValue("@LinkzaViseoMjestu", txtLinkZaViseoMjestu.Text);
cmd.Parameters.AddWithValue("@Regija", ddRegija.SelectedValue);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Conn.Close();
Response.Write(ex.Message);
Wizard1.ActiveStepIndex = 0;
}
}
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
if (e.CurrentStepIndex == 0)
{
SaveDataDB();
}
if (e.CurrentStepIndex == 1)
{
//Register user into the database not hear because wizard have one step only
// SaveDataDB();
}
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (ddRegija.SelectedIndex == 0)
args.IsValid = false;
}
protected void CustomValidatorPozicija_ServerValidate(object source, ServerValidateEventArgs args)
{
string ConnStr = ConfigurationManager.ConnectionStrings["croestate_dbConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(ConnStr);
try
{
Conn.Open();
String sqlQuery = "SELECT Pozicija FROM PozicijaObjekta WHERE Pozicija='" + txtPozicija.TemplateControl + "'";
SqlCommand cmd = new SqlCommand(sqlQuery, Conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read() == true)
args.IsValid = false;
}
catch (Exception ex)
{
Conn.Close();
Response.Write(ex.Message);
Wizard1.ActiveStepIndex = 0;
}
}
}
View 10 Replies
View Related
Apr 24, 2004
Hi, I have a problem when I insert a date in a datetime field in a MSSQLServer.
That's my problem:
if the server is in english version, I have to insert date with this code:
DateTime.Today.ToString("MM/dd/yyyy")
instead if the server is in italian version, I have to insert date with this code:
DateTime.Today.ToString("dd/MM/yyyy")
Is there a way to insert a date in standard way, without knowing the server version?
bye and thanks in advance
View 3 Replies
View Related
Dec 17, 2004
Edited by SomeNewKid. Please post code between <code> and </code> tags.
This is probaly the easiest question you've ever read but here goes.
I have a simple checkbox value that i want to insert into the database but whatever i do it does not seem to let me.
Here is my code:
Sub AddSection_Click(Sender As Object, e As EventArgs)
Dim myCommand As SqlCommand
Dim insertCmd As String
' Build a SQL INSERT statement string for all the input-form
' field values.
insertCmd = "insert into Customers values (@SectionName, @SectionLink, @Title, @NewWindow, @LatestNews, @Partners, @Support);"
' Initialize the SqlCommand with the new SQL string.
myCommand = New SqlCommand(insertCmd, myConnection)
' Create new parameters for the SqlCommand object and
' initialize them to the input-form field values.
myCommand.Parameters.Add(New SqlParameter("@SectionName", SqlDbType.nVarChar, 50))
myCommand.Parameters("@SectionName").Value = Section_name.Value
myCommand.Parameters.Add(New SqlParameter("@SectionLink", SqlDbType.nVarChar, 80))
myCommand.Parameters("@SectionLink").Value = Section_link.Value
myCommand.Parameters.Add(New SqlParameter("@Title", SqlDbType.nVarChar, 50))
myCommand.Parameters("@Title").Value = Section_title.Value
If New_window.Checked = false Then
myCommand.Parameters.Add(New SqlParameter("@NewWindow", SqlDbType.bit, 1))
myCommand.Parameters("@NewWindow").Value = 0
else
myCommand.Parameters.Add(New SqlParameter("@NewWindow", SqlDbType.bit, 1))
myCommand.Parameters("@NewWindow").Value = 1
End If
If Latest_news.Checked = false Then
myCommand.Parameters.Add(New SqlParameter("@LatestNews", SqlDbType.bit, 1))
myCommand.Parameters("@LatestNews").Value = 0
else
myCommand.Parameters.Add(New SqlParameter("@LatestNews", SqlDbType.bit, 1))
myCommand.Parameters("@LatestNews").Value = 1
End If
If Partners.Checked = false Then
myCommand.Parameters.Add(New SqlParameter("@Partners", SqlDbType.bit, 1))
myCommand.Parameters("@Partners").Value = 0
else
myCommand.Parameters.Add(New SqlParameter("@Partners", SqlDbType.bit, 1))
myCommand.Parameters("@Partners").Value = 1
End If
If Support.Checked = false Then
myCommand.Parameters.Add(New SqlParameter("@Support", SqlDbType.bit, 1))
myCommand.Parameters("@Support").Value = 0
else
myCommand.Parameters.Add(New SqlParameter("@Support", SqlDbType.bit, 1))
myCommand.Parameters("@Support").Value = 1
End If
myCommand.Connection.Open()
' Test whether the new row can be added and display the
' appropriate message box to the user.
Try
myCommand.ExecuteNonQuery()
Message.InnerHtml = "Record Added<br>" & insertCmd
Catch ex As SqlException
If ex.Number = 2627 Then
Message.InnerHtml = "ERROR: A record already exists with " _
& "the same primary key"
Else
Message.InnerHtml = "ERROR: Could not add record, please " _
& "ensure the fields are correctly filled out"
Message.Style("color") = "red"
End If
End Try
myCommand.Connection.Close()
BindGrid()
End Sub
Any response would be appreciated
View 2 Replies
View Related
Sep 13, 2004
I have a colum of numbers, which datatype is nvarchar;
157853
4389
1999999999556
4568987
I need to insert a hyphen, 3 spaces from the right (to left) My numbers would look like this:
157-853
4-389
1999999999-556
4568-987
...do I use the rtrim function ?...what would the syntax look like ?
Thank you
View 3 Replies
View Related
Oct 7, 2004
I've just noticed some strange behavior that seems like a bug to me.
It's much easier to follow an example of it that to outright explain it, so here goes.
I have a table defined with a NOT NULL constraint on a column and a default clause:
-- DROP TABLE TestTable
CREATE TABLE TestTable ( TestField0 varchar(10), TestField1 varchar(10) NOT NULL DEFAULT ('a') )
I have a view defined on the table, in this example case, the view just mirrors the table one to one:
-- DROP VIEW TestView
CREATE VIEW TestView as SELECT TestField0, TestField1 FROM TestTable
So far so good, if I run this statement, it works as I would expect and inserts the value and the default goes into the other field:
INSERT INTO TestView (TestField0) SELECT 'test'
Now... If I add an INSTEAD OF trigger to the view, and have it perform the insert for me, I get an error with the same insert stmt:
-- DROP TRIGGER TestTrigger
CREATE TRIGGER TestTrigger ON TestView
INSTEAD OF INSERT AS
BEGIN
INSERT INTO TestTable (TestField0, TestField1)
SELECT TestField0, COALESCE(TestField1, 'X')
FROM inserted
END
Notice the trigger will ensure that a null value cannot be inserted into TestField1. If I run this insert stmt though I get an error:
INSERT INTO TestView (TestField0) SELECT 'test'
Server: Msg 233, Level 16, State 2, Line 1
The column 'TestField1' in table 'TestView' cannot be null.
Am I missing something or is this a bug?
Thanks
View 1 Replies
View Related
Jul 20, 2005
Hi, I'm trying to store large strings to a database, so am using thetext field type (LongText). I have used this before when storing thehtml of a webpage, and was able to store more than 255 characters byusing just a normal update sql statement. Now I'm trying to store thebody of research papers, and must be doing something different, as Ican only store 255 characters.Can someone explain why SQL Server doesn't like what I am doing -should I be using the WriteText / UpdateText function? If so, pleaseexplain by example how I would do that, and why doing that works.Thanks so much,Iain
View 5 Replies
View Related
Sep 17, 2015
How to modify values in a SQL Database. In the table PRDDEmpmaster there is a field called email_address, and for those fields that have a value I need to change that value to add { } opening/closing "curly braces" to that field.Â
For example,
RPARSONS@YAHOO.COM becomes
{RPARSONS@YAHOO.COM} . Nulls/empty fields remain as is.   Â
View 6 Replies
View Related