जब मैं अपने वीबी ऐप से एक्सेल फाइल अपलोड करता हूं, तो यह पहली बार ठीक होता है। अगर मैं दूसरी बार कोशिश करता हूं तो मुझे यह त्रुटि हो रही है: प्रक्रिया फ़ाइल (पथ) तक नहीं पहुंच सकती क्योंकि यह किसी अन्य प्रक्रिया द्वारा उपयोग की जा रही है। नीचे मेरा कोड है:
Dim fd As OpenFileDialog = New OpenFileDialog()
fd.Title = "Open File Dialog"
fd.InitialDirectory = "C:\"
fd.Filter = "All files (*.xlsx)|*.xlsx|All files (*.xlsx)|*.xlsx"
fd.FilterIndex = 2
fd.RestoreDirectory = True
Dim myStream As Stream = Nothing
If fd.ShowDialog() = DialogResult.OK Then
Try
myStream = fd.OpenFile()
If (myStream IsNot Nothing) Then
workbook = APP.Workbooks.Open(fd.FileName)
worksheet = workbook.Worksheets("sheet1")
TextBox1.Text = worksheet.Cells(1, 7).Value
TextBox2.Text = worksheet.Cells(2, 7).Value
TextBox3.Text = worksheet.Cells(3, 7).Value
l1.Text = worksheet.Cells(2, 1).Value * 10
w1.Text = worksheet.Cells(2, 2).Value * 10
q1.Text = worksheet.Cells(2, 3).Value
p1.Text = worksheet.Cells(2, 4).Value..........
Dim Values(119, 3) As String
Values(0, 0) = l1.Text
Values(0, 1) = w1.Text
Values(0, 2) = q1.Text
Values(0, 3) = p1.Text.........
Dim add As Integer = 0
Dim pressing As Integer = 0
If adding.Text = "50" Or adding.Text = "" Then
add = 50
Else
add = Convert.ToInt16(adding.Text)
End If
If press.Text = "20" Or press.Text = "" Then
pressing = 20
Else
pressing = Convert.ToInt16(press.Text)
End If
Dim l As Integer
Dim w As Integer
Dim machinearea As Integer
Dim connetionString As String
Dim cnn As SqlConnection
connetionString = "Data Source=.;Initial Catalog=lumber;User ID=sa;Password=sasql"
cnn = New SqlConnection(connetionString)
Dim cmd As SqlCommand
Dim myreader As SqlDataReader
Dim query As String
query = "SELECT length,width from marea"
cmd = New SqlCommand(query, cnn)
cnn.Open()
myreader = cmd.ExecuteReader()
If myreader.Read() Then
l = myreader.Item("length")
w = myreader.Item("width")
End If
cnn.Close()
machinearea = l * w
Dim allTextBoxes2 = From txt In Me.Panel1.Controls.OfType(Of TextBox)()
Order By txt.TabIndex
Dim txtList2 = allTextBoxes2.ToList()
For i As Int32 = 0 To txtList2.Count - 1
Dim thisTxt = txtList2(i)
Dim nextIndex = If(i + 1 >= txtList2.Count, 0, i + 1)
Dim prevIndex = If(i - 1 < 0, txtList2.Count - 1, i - 1)
Dim nextTxt = txtList2(nextIndex)
Dim prevTxt = txtList2(prevIndex)
Dim testInt As Integer = 0
If thisTxt.Text = "0" Then
thisTxt.Clear()
End If
Next
Dim allTextBoxes = From txt In Me.Panel1.Controls.OfType(Of TextBox)()
Order By txt.TabIndex
Dim txtList = allTextBoxes.ToList()
For i As Int32 = 0 To txtList.Count - 1
Dim thisTxt = txtList(i)
For j = 2 To -1
For k = 1 To 4
thisTxt.Text = worksheet.Cells(i + j, k).Value
Next
Next
Next
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally
' Check this again, since we need to make sure we didn't throw an exception on open.
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If
2 जवाब
Try
myStream = fd.OpenFile()
If (myStream IsNot Nothing) Then
workbook = APP.Workbooks.Open(fd.FileName, ReadOnly:=True, Notify:=False)
worksheet = workbook.Worksheets("sheet1")
...
Finally
' Check this again, since we need to make sure we didn't throw an exception on open.
If (myStream IsNot Nothing) Then
myStream.Close()
End If
If (workbook IsNot Nothing) Then
workbook.Close()
End If
End Try
सुनिश्चित करें कि एप्लिकेशन बंद है और कोई प्रक्रिया नहीं चल रही है या यह आपको वह त्रुटि देगा।
संबंधित सवाल
नए सवाल
vb.net
Visual Basic.NET (VB.NET) एक बहु-प्रतिमान, प्रबंधित, प्रकार-सुरक्षित, ऑब्जेक्ट-उन्मुख कंप्यूटर प्रोग्रामिंग भाषा है। C # और F # के साथ, यह .NET फ्रेमवर्क को लक्षित करने वाली मुख्य भाषाओं में से एक है। VB.NET को Microsoft के Visual Basic 6 (VB6) के विकास के रूप में देखा जा सकता है लेकिन Microsoft .NET फ्रेमवर्क पर लागू किया जा सकता है। VB6, VBA या VBScript प्रश्नों के लिए इस टैग का उपयोग न करें।