application client serveur vb.NET
Bonsoir à tous,
je suis entrain de developper une application client serveur avec vb.net sous visual studio2008 avec une base de données sql server2008.
Pour resumer un peu mon application comme premiere etape je dois parcourir et lire plusieurs fichiers excel et afficher leur contenu dans la base sqlserver qui contient une seule table. Tout d'abord j'ai créer un projet de type asp.net web service application pour le côté serveur et un projet de type windows form pour le côté client.
Est-ce-que c'est juste ce que j'ai fait comme 1ér etape? Sinon est ce que je dois utliser le .NET remoting??
Et mon application doit accepter les connexions a distance c'est a dire le client peut acceder a l'application d'une autre machine autre que la machine du serveur. Comment faire ça??
Et voila le code du coté serveur est-ce-que c'est possible de travailler avec le datagrid au coté serveur car il m'affiche un message d'erreur
Citation:
datagridview n'es pas déclaré
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
' Pour autoriser l'appel de ce service Web depuis un script à l'aide d'ASP.NET AJAX, supprimez les marques de commentaire de la ligne suivante.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function Getfoldercount(ByVal strPath As String) As Integer
Try
Return System.IO.Directory.GetDirectories(strPath).Length()
Catch ex As Exception
Throw New Exception("Error" & ex.Message, ex)
End Try
End Function
<WebMethod()> _
Public Sub importer(ByVal strPath As String)
Dim connex1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Users\Maher\Documents\CDRs\nomdoss\nomfich;Extended Properties=""Excel 8.0;HDR=YES"""
Dim connex2 As OleDbConnection
connex2 = New OleDbConnection(connex1)
Dim cmdselect As OleDbCommand
cmdselect = New OleDbCommand("select * from [b00090438$]", connex2)
Dim adaptador As New OleDbDataAdapter
adaptador.SelectCommand = cmdselect
Dim ds As DataSet
ds = New DataSet
adaptador.Fill(ds)
dtg.DataSource=ds.Tables(0)
connex2.Close()
Dim connex3 As New SqlConnection
connex3.ConnectionString = "Data source=(RAHMA-PC);initial catalog=BaseCDR;Integrated Security=True"
connex3.Open()
Dim import As SqlBulkCopy
import = New SqlBulkCopy(connex3)
import.DestinationTableName = "Table_1"
import.WriteToServer(ds.Tables(0))
connex3.Close()
End Sub
<WebMethod()> _
Public Sub Insertion()
Dim nomfich As String
Dim nomdoss As String
Dim doss As Integer
Dim Nbrep As Integer
Dim Nbfich As Integer
Dim fich As Integer
Nbrep = Getfoldercount("C:\Users\Maher\Documents\CDRs")
For doss = 1 To Nbrep
nomdoss = "cdr" & doss
Process.Start("C:\Users\Maher\Documents\CDRs\nomdoss")
Nbfich = My.Computer.FileSystem.GetFiles("C:\Users\Maher\Documents\CDRs\nomdoss", FileIO.SearchOption.SearchTopLevelOnly, "b00090438*").Count
For fich = 1 To Nbfich
nomfich = "b00090438_" & fich & ".xls"
importer("C:\Users\Maher\Documents\CDRs\nomdoss\nomfich")
Next
Next
End Sub
End Class |
Et quand je fais appel a la fonction insertion au coté client il m'affiche un message d'erreur
Citation:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidCastException: Conversion from string "cdr1" to type 'Integer' is not valid. ---> System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDou
Voila le code du coté client
Code:
1 2 3 4 5 6 7 8 9 10 11
| Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Net
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim serv As New localhost.Service1()
serv.Insertion()
End Sub
End Class |
Et merci d'avance :)