bonjour
je voulais savoir comment changer une variable de type int dans SQL server 2005 en une variable de type
varchar dans vb.
J'ai fait ma base de donnée dans sql server 2005 avec des procedures stockées qui ont des variables de type int
Je dois maintenent utiliser vb 2005 pour faire l'interface graphique pour utiliser ma procedure stockée.
seulement l'interface graphique utilise des variables de type varchar pour entrer les parametres de calcul de ma
procedure stockée alors que ces parametres sont de type int dans sql server.
Donc je suis à la recherche d'une solution me permetant de resoudre ce probléme.
voici le code de ma procedure stockéeset ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[calculprix]
@transporteur int, -- numéro de transporteur
@zone int, -- numéro de zone
@quantite int, -- qte (ex: 200)
@designation varchar(30) -- type de qte (ex: kg)
AS
BEGIN
SET NOCOUNT ON;
declare @nom_du_transporteur as varchar(50)
declare @nom_zone as varchar(50)
declare @prix_transport as int
declare @tranche_colis as int
declare @valeur_inferieure as int
declare @valeur_superieure as int
declare @designation_tranche as varchar (50)
select @nom_du_transporteur = nomtransporteur from transporteurs where id = @transporteur
print 'LE NOM DU TRANSPORTEUR EST : '
print @nom_du_transporteur
select @nom_zone = designation from zones where id = @zone
print 'LE NOM DE LA ZONE DE LIVRAISON EST : '
print @nom_zone
select* from tranches where [transporteur] = @transporteur and [designation] = @designation and [inf] <= @quantite and [sup] >= @quantite
print 'LE POIDS DU COLIS EST : '
print @quantite
select @tranche_colis = id from tranches where [transporteur] = @transporteur and [designation] = @designation
print 'LA TRANCHE DE COLIS EST : '
print @tranche_colis
select @valeur_inferieure = inf from tranches where [transporteur] = @transporteur and [designation] = @designation
print 'LA VALEUR MINIMALE DE LA TRANCHE EST : '
print @valeur_inferieure
select @valeur_superieure = sup from tranches where [transporteur] = @transporteur and [designation] = @designation
print 'LA VALEUR MAXIMALE DE LA TRANCHE EST : '
print @valeur_superieure
select @designation = designation from tranches where [transporteur] = @transporteur and [designation] = @designation
print 'L''UNITE DE MESURE DE LA TRANCHE EST : '
print @designation
select @prix_transport = prix from tarifs where [zone ]= @zone and [transporteur] = @transporteur and [tranche] = @tranche_colis
print 'LE PRIX DE LA PRESTATION DE TRANSPORT EST DE : '
print @prix_transport
END
et voici le code de l'interface graphique Public Class Form1
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub ComboBox1_ContextMenuChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.ContextMenuChanged
End Sub
Private Sub ComboBox4_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox4.SelectedIndexChanged
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label2.Text = "le prix de la prestation est : "
Dim conn As New SqlClient.SqlConnection("database="nom_de_ma_base";data source="nom_du_server";user id="identifient";pwd=le_mot_de_passe")
Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand
command.Connection = conn
command.CommandType = CommandType.StoredProcedure
command.CommandText = "calculprix"
command.CommandText = "Select * From transporteurs Where col1 = @id And col2 = @str";
command.Parameters.Add("transporteur", SqlDbType.Int).Value = ComboBox1.SelectedText
command.Parameters.Add("zone", SqlDbType.Int).Value = ComboBox2.SelectedText
command.Parameters.Add("quantite", SqlDbType.Int).Value = Val(TextBox1.Text)
command.Parameters.Add("designation", SqlDbType.VarChar).Value = ComboBox4.SelectedText
conn.Open()
command.ExecuteNonQuery()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class


