You are on page 1of 3

Connection String

============================
<connectionStrings>
<add name="ReelzConnectionString" connectionString="Data Source=ROBEL;Initial
Catalog=Reelz;User ID=sa;Password=kaushik"
providerName="System.Data.SqlClient" />
</connectionStrings>
====================================
Under Button
---------------------------------------------------------------------
Dim objParam1 As SqlParameter = New SqlParameter
Dim objParam2 As SqlParameter = New SqlParameter
Dim objReturnParam1 As SqlParameter = New SqlParameter
Dim con As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnecti
on(ConfigurationManager.ConnectionStrings("ReelzConnectionString").ConnectionStr
ing)
Dim MyCmd As New SqlCommand
MyCmd.CommandType = CommandType.StoredProcedure
MyCmd.CommandText = "Insertcity"
MyCmd.Connection = con
con.Open()
objParam1 = MyCmd.Parameters.Add("@state_id", SqlDbType.Int)
objParam1.Value = rtkt_ddstate.SelectedValue
objParam2 = MyCmd.Parameters.Add("@city_name", SqlDbType.VarChar)
objParam2.Value = Trim(rtkt_addcity.Text)
objReturnParam1 = MyCmd.Parameters.Add("@flagcheck", SqlDbType.Int)
objReturnParam1.Direction = ParameterDirection.ReturnValue
MyCmd.ExecuteNonQuery()
If objReturnParam1.Value.ToString = "0" Then
lb.Text = "<b style='font-size:11px; color:#FF0000'>Already Data Ins
erted !</b>"
ElseIf objReturnParam1.Value.ToString = "1" Then
lb.Text = "<b style='font-size:11px; color:#339900'>Data Add Success
fully</b>"
End If
con.Close()
con.Dispose()
MyCmd.Dispose()
rtkt_addcity.Text = ""
==============================================
page_Load Viewer
--------------------------------------------------------------------------------
-------------------------
Dim con As String = ConfigurationManager.ConnectionStrings("ofoodiesConnection
String").ConnectionString
Dim kh As SqlConnection = New SqlConnection(con)
Dim myCmd As SqlCommand = New SqlCommand("SELECT rest_zone_id,rest_zone_
name From ofoodies_zone where rest_city_zone=" + rest_city.SelectedValue + " and
rest_zone_activation=1 Order By rest_zone_name", kh)
kh.Open()
Dim myReader As SqlDataReader = myCmd.ExecuteReader()
rest_zone.DataSource = myReader
rest_zone.DataTextField = "rest_zone_name"
rest_zone.DataValueField = "rest_zone_id"
rest_zone.AutoPostBack = True
rest_zone.DataBind()
kh.Close()
myReader.Close()
kh.Dispose()
myCmd.Dispose()
rest_state.Items.Remove(" - Select City - ")
rest_zone.Items.Insert(0, " - Select Zone - ")
======================================================
Image Add
--------------------------------------------------------------------------------
-------------------------
Dim str As String = "~/BA/" + rest_city.SelectedItem.Text + "/Deals/"
Dim imagefolder = Server.MapPath(str)
Dim savepath As String
Dim spat As String = Nothing
Dim tstamp As String = Format(System.DateTime.UtcNow, "ddMMyyyyhhmmsstt"
)
If rest_menu_card_upload.HasFile = True Then
Try
tstamp = tstamp.Replace(":", "")
tstamp = tstamp.Replace("/", "")
savepath = imagefolder & rmspos & "_Deals_" & tstamp & rest_menu
_card_upload.FileName
rest_menu_card_upload.SaveAs(savepath)
spat = str.Replace("~/", "").ToLower + rmspos + "_Deals_" + tsta
mp + rest_menu_card_upload.FileName.ToLower
s1.Text = "<b style='font-size:11px; color:#339900'><a class=""t
humbnail"" href=""#thumb"" style=""text-decoration:none"">Preview<span><img src=
'../" + spat + "' width=""150px"" height=""150px"" /></span></a></b>"
Catch ex As Exception
s1.Text = "<b style='font-size:11px; color:#FF0000'>Error</b>"
spat = ""
End Try
Else
s1.Text = "<b style='font-size:11px; color:#FF0000'>Error</b>"
spat = ""
End If
objParam7 = MyCmd.Parameters.Add("@rest_menu_card_upload", SqlDbType.Var
Char)
objParam7.Value = spat
=============================================================
Database
---------------------------------------
USE [Reelz]
GO
/****** Object: StoredProcedure [dbo].[Insertcity] Script Date: 05/27/2011 2
0:59:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Insertcity]
(
@state_id int,
@city_name varchar(MAX)
)
AS
Declare @FlgChk int
IF EXISTS(SELECT city_id FROM reelz_city WHERE state_id = @state_id AND city_nam
e = @city_name )
BEGIN
--This means it exists, return it to ASP and tell us
--PRINT 'This record already exists!'
set @FlgChk=0
END
ELSE
BEGIN
--This means the record isn't in there already, let's go ahead and add it
SELECT 'Record Added'
INSERT into reelz_city(state_id,city_name,city_activate) VALUES(@state_id,@cit
y_name,1)
--PRINT 'Record Added'
set @FlgChk=1
END
return @FlgChk

You might also like