May 27, 2007
Okay, so i'll just let you know right now, that i suck at making quries
i'm testing out a 2k5 eval copy of Sql Server (if i like, i'll migrate from 2k)
i have a db of almost 4 million names, with no indexes, and i'm trying to have
Sql tune a procedure that i wrote to see what it recommends for adjustments.
but for some reason it comes up with no results. any ideas why?
--Update
just noticed that if i type in the full query (not in the procedure form)
it recommends some indexes for me. is there any why to get recommendations
though the stored procedure below? i have about 112 quries that i want
to analyse, i could change them to actual quries if i had to, but it'd
take awhile
Current Table DDL:
USE [Test]
GO
/****** Object: Table [dbo].[mortgage] Script Date: 05/27/2007 01:52:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[mortgage](
[fips_state] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[state_abbrv] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[zip] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[zip_four] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[del_point] [char](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[car_rte] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[city_abbrv] [varchar](13) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[city] [varchar](28) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[addr_house_num] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[addr_pre_dir] [varchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[addr_st_name] [varchar](28) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[addr_st_suff] [varchar](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[addr_post_dir] [varchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[addr_unit_des] [varchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[addr_unit_desnum] [varchar](8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[address1] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[fips_cnty] [char](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[county_name] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[census_tract] [char](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[census_block] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[lattitude] [char](9) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[longitude] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[fips_ispsa] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[wealth_rating] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[time_zone] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[phone] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[homeowner] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[est_inc] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_fname] [varchar](15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_mi] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_lname] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_title] [varchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_gender] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_dob] [char](8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_ageconf] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_age] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_msconf] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per1_ms] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per2_fname] [char](15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per2_mi] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per2_lname] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per2_title] [varchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per2_gender] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per2_dob] [char](8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per2_ageconf] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[per2_age] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_pres] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_0_3] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_0_3_gender] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_4_6] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_4_6_gender] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_7_9] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_7_9_gender] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_10_12] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_10_12_gender] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_13_18] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[child_13_18_gender] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[religious_contrib] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[political_contrib] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[health_contrib] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[general_contrib] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[hm_purprice] [char](8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[hm_purdate] [char](8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[hm_year_build] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[donate_env] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[char_contrib] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[pres_cc] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[pres_perm_cc] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_mtg_amnt] [char](8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_mtg_lender_name] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_mtg_rate] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_mtg_rate_t] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_mtg_loan_t] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[dnc] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_refi_deed_date] [char](8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_refi_amnt] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_refi_lender_name] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_refi_rate_t] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_refi_month_term] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[oo_refi_loan_t] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FullName] [varchar](40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[address] [varchar](40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Source] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[citystate] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[countystate] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[areacode] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
Stored Procedure:
USE [Test]
GO
/****** Object: StoredProcedure [dbo].[search_orders_2] Script Date: 05/27/2007 01:53:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
create PROCEDURE [dbo].[search_orders_2]
@lowagenvarchar(10)=null,
@highagenvarchar(10)=null,
@highwealthnvarchar(10)=null,
@lowwealthnvarchar(10)=null,
@highpurpricenvarchar(10)=null,
@lowpurpricenvarchar(10)=null,
@lowmtgamtnvarchar(10)=null,
@highmtgamtnvarchar(10)=null,
@lowincomevarchar(3)=null,
@highincomevarchar(3)=null,
@marriedstatvarchar(3)=null,
@lowyearbuildvarchar(4)=null,
@highyearbuildvarchar(4)=null,
@mtgpresstatvarchar(3)=null,
@lenderpresstatvarchar(3)=null,
@ratetsvarchar(3)=null,
@loantsvarchar(10)=null,
@childstatvarchar(3)=null,
@homeownerstatvarchar(10)=null,
@lowpurdatevarchar(8)=null,
@highpurdatevarchar(8)=null,
@addresstype varchar(3)= null,
@SPSirvarchar(3)= null,
@debttypevarchar(3)= null,
@dwelltypevarchar(3)= null,
@zipselectnvarchar(4000)=null,
@acselectnvarchar(4000)=null,
@stselectnvarchar(4000)=null,
@cityselectnvarchar(4000)=null,
@counselectnvarchar(4000)=null,
@tablenamenvarchar(2)=null,
@orderbynvarchar(2)=null,
@Zipcode char(11)=null,
@milesfloat=null,-- as
@debug bit = 0 AS
DECLARE @sql nvarchar(4000),
@paramlist nvarchar(4000),
@highlatitude float,
@lowlatitudefloat,
@HighLongitudefloat,
@LowLongitude float,
@StartLatitudefloat,
@StartLongitude float,
@LatitudeRange float,
@LongitudeRange float
if @miles>0
SELECT @StartLatitude = lat, @StartLongitude = lng FROM zipinfo2 WHERE zip = @Zipcode
Set @LongitudeRange = @Miles / (((Cos(@StartLatitude * pi() / 180) * 6076.0) / 5280.0) * 60)
Set @LatitudeRange = @Miles / 69.045454545454545454545454545455
Set @LowLatitude = @StartLatitude - @LatitudeRange
Set @HighLatitude = @StartLatitude + @LatitudeRange
Set @LowLongitude = @StartLongitude - @LongitudeRange
Set @HighLongitude = @StartLongitude + @LongitudeRange
set @sql = ''
if @orderby is null set @orderby='1'
if @tablename is null set @tablename='1'
if @spsir='1'
select @sql = @sql+ 'SELECT '
+case @orderby
when 1 then 'o.state_abbrv, count(o.state_abbrv) '
when 2 then 'o.county_name, o.state_abbrv, count(o.state_abbrv) '
when 3 then 'o.city, o.state_abbrv, count(o.state_abbrv) '
when 4 then 'o.zip, count(o.zip) '
end + 'as kount FROM dbo.'
+ case @tablename
when 1 then 'mortgage'
when 2 then 'homeowner'
when 3 then 'condnc'
when 4 then 'mailable'
end +' o with (nolock) left join dbo.Spanish s on o.per1_lname = s.lname'
if @spsir='2'
select @sql = @sql+ 'SELECT distinct '
+case @orderby
when 1 then 'o.state_abbrv, count(o.state_abbrv) '
when 2 then 'o.county_name, o.state_abbrv, count(o.state_abbrv) '
when 3 then 'o.city, o.state_abbrv, count(o.state_abbrv) '
when 4 then 'o.zip, count(o.zip) '
end + 'as kount FROM dbo.'
+ case @tablename
when 1 then 'mortgage'
when 2 then 'homeowner'
when 3 then 'condnc'
when 4 then 'mailable'
End +' o with (nolock) inner join dbo.Spanish s on o.per1_lname = s.lname'
if @spsir='ALL' or @spsir is null
SELECT @sql = 'SELECT '
+case @orderby
when 1 then 'o.state_abbrv, count(o.state_abbrv) '
when 2 then 'o.county_name, o.state_abbrv, count(o.state_abbrv) '
when 3 then 'o.city, o.state_abbrv, count(o.state_abbrv) '
when 4 then 'o.zip, count(o.zip) '
end + 'as kount FROM dbo.'
+ case @tablename
when 1 then 'mortgage'
when 2 then 'homeowner'
when 3 then 'condnc'
when 4 then 'mailable'
End + ' o with (nolock)'
select @sql=@sql+' WHERE 1 = 1'
if @spsir='1'
select @sql = @sql+ ' and s.lname is null'
IF @lowage<>0 and @lowage is not null
SELECT @sql = @sql + ' AND o.per1_age >= @xlowage'
IF @highage<>0 and @highage IS NOT null
SELECT @sql = @sql + ' AND o.per1_age <= @xhighage'
IF @lowincome<>'DF' and @lowincome IS NOT NULL
SELECT @sql = @sql + ' AND o.est_inc >= @xlowincome'
IF @highincome<>'DF' and @highincome IS NOT NULL
SELECT @sql = @sql + ' AND o.est_inc <= @xhighincome'
IF @highwealth<>0 and @highwealth IS NOT NULL
SELECT @sql = @sql + ' AND o.wealth_rating <= @xhighwealth'
IF @lowwealth<>0 and @lowwealth IS NOT NULL
SELECT @sql = @sql + ' AND o.wealth_rating >= @xlowwealth'
IF @highpurprice<>0 and @highpurprice IS NOT NULL
SELECT @sql = @sql + ' AND o.hm_purprice <= @xhighpurprice'
IF @lowpurprice<>0 and @lowpurprice IS NOT NULL
SELECT @sql = @sql + ' AND o.hm_purprice >= @xlowpurprice'
IF @lowyearbuild<>'DF' and @lowyearbuild IS NOT NULL
SELECT @sql = @sql + ' AND o.hm_year_build >= @xlowyearbuild'
IF @highyearbuild<>'DF' and @highyearbuild IS NOT NULL
SELECT @sql = @sql + ' AND o.hm_year_build <= @xhighyearbuild'
IF @lowmtgamt<>0 and @lowmtgamt IS NOT NULL
SELECT @sql = @sql + ' AND o.oo_mtg_amnt >= @xlowmtgamt'
IF @highmtgamt<>0 and @highmtgamt IS NOT NULL
SELECT @sql = @sql + ' AND o.oo_mtg_amnt <= @xhighmtgamt'
IF @lowpurdate<>'DF' and @lowpurdate IS NOT NULL
SELECT @sql = @sql + ' AND o.hm_purdate >= @xlowpurdate'
IF @highpurdate<>'DF' and @highpurdate IS NOT NULL
SELECT @sql = @sql + ' AND o.hm_purdate <= @xhighpurdate'
IF @marriedstat in ('M','S')
SELECT @sql = @sql + ' AND o.per1_ms = @xmarriedstat'
IF @ratets in ('V','F')
SELECT @sql = @sql + ' AND o.oo_mtg_rate_t = @xratets'
IF @homeownerstat in ('H','R')
SELECT @sql = @sql + ' AND o.homeowner = @xhomeownerstat'
IF @childstat in ('Y','N')
SELECT @sql = @sql + ' AND o.child_pres = @xchildstat'
IF @lenderpresstat ='Y'
SELECT @sql = @sql + ' AND o.oo_mtg_lender_name<>'' '''
IF @lenderpresstat ='N'
SELECT @sql = @sql + ' AND o.oo_mtg_lender_name='' '''
IF @mtgpresstat='Y'
SELECT @sql = @sql + ' AND o.oo_mtg_amnt>0'
IF @mtgpresstat='N'
SELECT @sql = @sql + ' AND o.oo_mtg_amnt=0'
IF @loants<>'DF' and @loants IS NOT NULL
SELECT @sql = @sql + ' and o.oo_mtg_loan_t in ( ''' + REPLACE( @loants, N',', N''',''' ) + N''' )'
if @dwelltype='S'
SELECT @sql = @sql + ' and o.addr_unit_desnum='' '''
if @dwelltype='M'
SELECT @sql = @sql + ' and o.addr_unit_desnum<>'' '''
if @DebtType='1'
select @sql = @sql + ' and o.pres_cc=''y'''
if @DebtType='2'
select @sql = @sql + ' and o.pres_perm_cc=''y'''
if @addresstype in ('1','3')
select @sql = @sql + ' and o.address1<>'' '''
if @acselect <> 'DF' or @stselect <> 'DF' or @cityselect <> 'DF' or @counselect <> 'DF' or @zipselect <>
'DF' or @miles<>0
SELECT @sql = @sql + ' and (1=2'
IF @acselect<>'DF' and @acselect IS NOT NULL
SELECT @sql = @sql + ' OR o.areacode in ( ''' + REPLACE( @acselect, N',', N''',''' ) + N''' )'
IF @stselect<>'DF' and @stselect IS NOT NULL
SELECT @sql = @sql + ' OR o.state_abbrv in ( ''' + REPLACE( @stselect, N',', N''',''' ) + N''' )'
IF @cityselect<>'DF' and @cityselect IS NOT NULL
SELECT @sql = @sql + ' OR o.citystate in ( ''' + REPLACE( @cityselect, N',', N''',''' ) + N''' )'
IF @counselect<>'DF' and @counselect IS NOT NULL
SELECT @sql = @sql + ' OR o.countystate in ( ''' + REPLACE( @counselect, N',', N''',''' ) + N''' )'
IF @zipselect<>'DF' and @zipselect IS NOT NULL
SELECT @sql = @sql + ' OR o.zip in ( ''' + REPLACE( @zipselect, N',', N''',''' ) + N''' )'
if @miles>0
select @sql = @sql+ ' or o.zip in (SELECT z.zip FROM dbo.zipinfo2 z WHERE (z.Lat <= @HighLatitude
AND z.Lat >= @LowLatitude) AND (z.Lng <= @HighLongitude AND z.Lng >= @LowLongitude))'
if @acselect <> 'DF' or @stselect <> 'DF' or @cityselect <> 'DF' or @counselect <> 'DF' or
@zipselect <> 'DF' or @miles<>0
SELECT @sql = @sql + ')'
select @sql=@sql +case @orderby
when 1 then ' group by o.state_abbrv order by o.state_abbrv '
when 2 then ' group by o.state_abbrv,o.county_name order by o.state_abbrv,o.county_name '
when 3 then ' group by o.state_abbrv,o.city order by o.state_abbrv,o.city '
when 4 then ' group by o.zip order by o.zip '
end
IF @debug = 1
PRINT @sql
SELECT @paramlist = '@xlowageint,
@xhighageint,
@xlowincomenvarchar(4000),
@xhighincomenvarchar(4000),
@xmarriedstatnvarchar(4000),
@xhighwealthint,
@xlowwealthint,
@xhighpurpriceint,
@xlowpurpriceint,
@xlowyearbuildnvarchar(4000),
@xhighyearbuildnvarchar(4000),
@xlowmtgamtint,
@xhighmtgamtint,
@xmtgpresstatnvarchar(4000),
@xlenderpresstatnvarchar(4000),
@xratetsnvarchar(4000),
@xloantsnvarchar(4000),
@xchildstatnvarchar(4000),
@xhomeownerstatnvarchar(4000),
@xlowpurdatenvarchar(4000),
@xhighpurdatenvarchar(4000),
@xzipselectnvarchar(4000),
@xacselectnvarchar(4000),
@xstselectnvarchar(4000),
@xcityselectnvarchar(4000),
@xcounselectnvarchar(4000),
@highlatitude float,
@lowlatitudefloat,
@HighLongitudefloat,
@LowLongitude float,
@StartLatitudefloat,
@StartLongitude float,
@LatitudeRange float,
@LongitudeRange float'
EXEC sp_executesql @sql, @paramlist,
@lowage,
@highage,
@lowincome,
@highincome,
@marriedstat,
@highwealth,
@lowwealth,
@highpurprice,
@lowpurprice,
@lowyearbuild,
@highyearbuild,
@lowmtgamt,
@highmtgamt,
@mtgpresstat,
@lenderpresstat,
@ratets,
@loants,
@childstat,
@homeownerstat,
@lowpurdate,
@highpurdate,
@zipselect,
@acselect,
@stselect,
@cityselect,
@counselect,
@highlatitude,
@lowlatitude ,
@HighLongitude,
@LowLongitude,
@StartLatitude,
@StartLongitude,
@LatitudeRange,
@LongitudeRange
Query to analyse:
Exec Search_orders_2
@mtgpresstat = 'Y',
@homeownerstat = 'H',
@stselect = 'PA,RI,SC',
@addresstype = '2',
@spsir = 'ALL',
@debttype = 'ALL',
@dwelltype = 'ALL',
@tablename = '1',
@orderby = '1';
View 20 Replies
View Related
Jan 4, 2005
To all,
Here's the error:
Input string was not in a correct format.
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.FormatException: Input string was not in a correct format.
Source Error:
Line 159:
Line 160:objConn.Open()
Line 161:objCmd.ExecuteNonQuery()
Line 162:objConn.Close()
Line 163:
Source File: C:FullerAviationSupplymanagecatalog.vb Line: 161
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +194
managecatalog.SubmitProd(Object s, EventArgs e) in C:FullerAviationSupplymanagecatalog.vb:161
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
Here's the code from my vb file:
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Protected WithEvents dgProductCatalog As datagrid
Protected WithEvents tbxProductName As TextBox
Protected WithEvents tbxInventory As TextBox
Protected WithEvents dgCatProd_Active As DropDownList
Protected WithEvents dlvendor As DropDownList
Protected WithEvents dlSubcat As DropDownList
Protected WithEvents btnLinkvend As Button
Protected WithEvents tbxshortdesc As TextBox
Protected WithEvents tbxlongdesc As TextBox
Protected WithEvents qtyPA As TextBox
Protected WithEvents pricePA As TextBox
Protected WithEvents qtyPB As TextBox
Protected WithEvents pricePB As TextBox
Protected WithEvents qtyPC As TextBox
Protected WithEvents pricePC As TextBox
Protected WithEvents sizeX As TextBox
Protected WithEvents dlX As DropDownList
Protected WithEvents sizeY As TextBox
Protected WithEvents dlY As DropDownList
Protected WithEvents sizeZ As TextBox
Protected WithEvents dlZ As DropDownList
Protected WithEvents weight As TextBox
Protected WithEvents dlweight As DropDownList
Protected WithEvents dgInsertProduct As Button
Protected WithEvents thumbfile As TextBox
Protected WithEvents mainfile As TextBox
Dim objDA As SqlDataAdapter
Dim objDS As New DataSet()
Dim objDX As New DataSet()
Dim objDV As New DataSet()
Dim objDU As New DAtaSet()
Dim objDW As New DAtaSet()
Dim objDT As DataTable
Dim objDR As DataRow
Dim objConn As SqlConnection = New SqlConnection(ConStr)
Sub Page_Load()
If Not IsPostBack Then
BindData()
End IF
End Sub
Sub BindData()
objDA = New SqlDataAdapter("GETCATALOG",objConn)
objDA.Fill(objDS, "MainCatalog")
objDT = objDS.Tables("Catalog")
dgProductCatalog.DataSource = objDS
dgProductCatalog.DataBind()
objDA = New SqlDataAdapter("GETSUBCAT",objConn)
objDA.Fill(objDX, "SubCat")
dlSubcat.DataSource = objDX
dlSubcat.DataValueField = "SubCat_ID"
dlSubcat.DataTextField = "SubCat_Name"
dlSubcat.DataBind()
objDA = New SqlDataAdapter("GETVENDOR",objConn)
objDA.Fill(objDV, "Vendor")
dlvendor.DataSource = objDV
dlvendor.DataValueField = "VendorID"
dlvendor.DataTextField = "CompanyName"
dlvendor.DataBind()
objDA = New SqlDataAdapter("GETSIZEUNITS",objConn)
objDA.Fill(objDU, "Units")
dlX.DataSource = objDU
dlX.DataValueField = "Size_ID"
dlX.DataTextField = "Size_Unit"
dlX.DataBind()
dlY.DataSource = objDU
dlY.DataValueField = "Size_ID"
dlY.DataTextField = "Size_Unit"
dlY.DataBind()
dlZ.DataSource = objDU
dlZ.DataValueField = "Size_ID"
dlZ.DataTextField = "Size_Unit"
dlZ.DataBind()
objDA = New SqlDataAdapter("GETWEIGHTUNITS",objConn)
objDA.Fill(objDW, "Units")
dlweight.DataSource = objDW
dlweight.DataValueField = "weight_unitID"
dlweight.DataTextField = "weight_Unit"
dlweight.DataBind()
End Sub
Sub SubmitProd(s As Object, e As EventArgs)
Dim objCmd As New SqlCommand("INSERTPRODUCT", objConn)
objCmd.CommandType = CommandType.StoredProcedure
objCmd.Parameters.Add("@prodName", tbxProductName.Text)
objCmd.Parameters.Add("@descShort", tbxshortdesc.Text)
objCmd.Parameters.Add("@descLong", tbxlongdesc.Text)
objCmd.Parameters.Add("@qtyPA", SqlDbType.int ).Value = qtyPA.Text
objCmd.Parameters.Add("@qtyPB", SqlDbType.int ).Value = qtyPB.Text
objCmd.Parameters.Add("@qtyPC", SqlDbType.int ).Value = qtyPC.Text
objCmd.Parameters.Add("@pricePA",SqlDbType.money).Value = pricePA.Text
objCmd.Parameters.Add("@pricePB",SqlDbType.money).Value = pricePB.Text
objCmd.Parameters.Add("@pricePC",SqlDbType.money).Value = pricePC.Text
objCmd.Parameters.Add("@vendorID", dlvendor.SelectedItem.Value)
objCmd.Parameters.Add("@inventoryAvail", SqlDbType.int).Value = tbxInventory.Text
objCmd.Parameters.Add("@imageThumb", thumbfile.Text)
objCmd.Parameters.Add("@imageLarge", mainfile.Text)
objCmd.Parameters.Add("@sizeX", sizeX.Text)
objCmd.Parameters.Add("@sizeY", sizeY.Text)
objCmd.Parameters.Add("@sizeZ", sizeZ.Text)
objCmd.Parameters.Add("@sizeUX", dlX.SelectedItem.Value)
objCmd.Parameters.Add("@sizeUY", dlY.SelectedItem.Value)
objCmd.Parameters.Add("@sizeUZ", dlZ.SelectedItem.Value)
objCmd.Parameters.Add("@weight", weight.Text)
objCmd.Parameters.Add("@prodActive", dgCatProd_Active.SelectedItem.Value)
objCmd.Parameters.Add("@weightU", dlweight.SelectedItem.Value)
objCmd.Parameters.Add("@SubCat_ID", dlSubcat.SelectedItem.Value)
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
tbxProductName.Text=""
tbxInventory.Text=""
tbxshortdesc.Text=""
tbxlongdesc.Text=""
qtyPA.Text=""
pricePA.Text=""
qtyPB.Text=""
pricePB.Text=""
qtyPC.Text=""
sizeX.Text=""
sizeZ.Text=""
sizeZ.Text=""
weight.Text=""
BindData()
End Sub
And here's the Stored Procedure:
CREATE PROCEDURE INSERTPRODUCT
(
@prodName nvarchar(50),
@descShort nvarchar(3000),
@descLong nvarchar(4000),
@qtyPA int,
@qtyPB int,
@qtyPC int,
@pricePA money,
@pricePB money,
@pricePC money,
@vendorID int,
@inventoryAvail int,
@imageThumb nvarchar,
@imageLarge nvarchar,
@sizeX nvarchar,
@sizeY nvarchar,
@sizeZ nvarchar,
@sizeUX int,
@sizeUY int,
@sizeUZ int,
@weight nvarchar,
@prodActive int,
@weightU int,
@SubCat_ID int
)
AS
INSERT INTO ProductCatalog (ProductName, Desc_Short, Desc_Long, qty_PerA, qty_PerB, qty_PerC, Price_PerA, Price_PerB, Price_PerC, VendorID, InventoryAvail, image_Thumb, image_Large, Size_X, Size_Y, Size_Z, SizeUnit_X, SizeUnit_Y, SizeUnit_Z, weight, Prod_Active, weight_unit, SubCat_ID) VALUES (@prodName, @descShort, @descLong, @qtyPA, @qtyPB, @qtyPC, @pricePA, @pricePB, @pricePC, @vendorID, @inventoryAvail, @imageThumb, @imageLarge, @sizeX, @sizeY, @sizeZ, @sizeUX, @sizeUY, @sizeUZ, @weight, @prodActive, @weightU, @SubCat_ID)
GO
Any help would be greatly appreciated.
Regards,
Seth
View 2 Replies
View Related