How can i store file name and file path to the database in DataGridview? - vb.net

i am trying to store file name and file path to the database by opening a OpenFileDiologue. here my codes.
NOTE: DB is already connected. properly showing data on datagridview and database is created with ms access named database1.accdb.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim showdialog1 As New OpenFileDialog
showdialog1.Filter = "Supported Video Files. | *.mp4; *.avi; *.wmv; *.mpg; *.mpeg; *.mov; *.webm; *.flv; *.mkv"
showdialog1.Title = "Add Supported Video Files."
If showdialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
AxWindowsMediaPlayer1.URL = showdialog1.FileName
Else
Exit Sub
End If
End Sub
here is a pic of my design. this will help you to understand me.
Click to View the pic
help me to store file name and file path to the database. hope i will get the easiest method.

It's simple :
Public sub Button1_Click
'your connection string
connection.open
Dim cmd as new Oledbcommand("Insert into
[tablename](columnname) values (#mycolumn)",yourconnectionstringname)
If openfiledialog1.dialogresult=dialogresult.ok then
cmd.parametres.add("#mycolumn",sqldbtype.varchar).value=openfiledialog1.filename
cmd.executenonquery()
connection.close
I hope this would help to achieve your goal

Related

Change connection string of access database in visual studio 2022

Ok so, basically i want to connect an access database (.mdb file) to my project. Now yes i have indeed connected it through the "data origin" wizard but the problem is that when i transfer the exe AND the database to another pc, it doesn't find it (obviously).
Dim appPath As String = My.Application.Info.DirectoryPath
Dim txtconnesione As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & appPath & "\Magazzino.mdb"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TableMagazzinoBindingSource.DataSource = txtconnesione
Me.TableMagazzinoTableAdapter.Fill(Me.MagazzinoDataSet.TableMagazzino)
End Sub
appPath is basically where the program gets started.
With this code it actually shows me the whole grid but it's empty, just like this:
i didn't used a connection string and i didn't copy it in the project (sorry for bad english, if you don't understand i'll try to explain better)

Asp.Net, VB, SQL Server Reporting Services..dynamically generated reports from directory to be viewed on report viewer on click?

I have an aspx webform that in it's vb code reads files that are .rdl from a directory and then lists them as say a button or hyper link etc. "reports are on local host report server"
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim FileLocation As DirectoryInfo = _
New DirectoryInfo("C:\inetpub\wwwroot\Reports")
Dim fi As FileInfo() = FileLocation.GetFiles("*.rdl")
For Each name As FileInfo In fi
' Dim i As Integer
Dim listed As New LinkButton
' listed.Attributes("CssClass") = "a"
' listed.Attributes("Class") = "a"
listed.Attributes("id") = "listed"
listed.Text = (name.Name)
mine.Controls.Add(listed)
'mine.InnerHtml = ""
'i = i + 1
Next
End Sub
and another that has a reportviewer. When a report was clicked, how can I send the name/value to the viewer and redirect to it?
Thank you very much
EDIT: i got to make the click redirect to the viewer with a string and have the viewer use that string,but with how much ever variation ive tried it still errors that
The path of the item 'salesreport.rdl' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. (rsInvalidItemPath)
this is the viewer code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
' Retrieve parameter from Route "Reports/{reportName}"
Dim reportName = Picks.Selecty
'Page.Title = reportName
ReportViewer1.ProcessingMode = ProcessingMode.Remote
Dim serverReport As ServerReport
ServerReport = ReportViewer1.ServerReport
serverReport.ReportServerUrl = New Uri("http://localhost/reportserver/")
serverReport.ReportPath = reportName
' reportName
'
' add parameters here
'Dim param As New ReportParameter("name", "value")
'serverReport.SetParameters(param)
serverReport.Refresh()
End If
End Sub
You could try the following.
Create a new page say ReportViewer.aspx which hosts your ReportViewer Control that recieves the name of the .RDL file as a query string.
In the First .aspx page, for every link you display, point the NavigateURL property to ReportViewer.aspx page and pass the name of the .RDL file as a QueryString.
Hope that helps
Thanks,
Prawin

How do I transfer data from Text Boxes in a form to an Access Table

I'm currently trying to write code for a form that has text boxes for a user to input the required data into which then with the use of button the data in the text boxes will be sent to an access table.
If you need any more information to help solve the problem I'm willing to provide it if you ask (I would upload pictures/screenshots but I need "10 reputation" apparently.
You can do this
Imports System.Data.OleDb
Public Class Form1
Dim AccessConection As OleDbConnection
Private Sub btSave_Click(sender As Object, e As EventArgs) Handles btSave.Click
Dim cmd As New OleDbCommand
Dim mySql As String
mySql = "INSERT INTO Customs (CustomName,Address) VALUES(#Name,#Address)"
Try
cmd.Parameters.AddWithValue("#Name", txName.Text)
cmd.Parameters.AddWithValue("#Address", txAddress.Text)
cmd.Connection = AccessConection
cmd.CommandType = CommandType.Text
cmd.CommandText = mySql
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Whatever you want to say..." & vbCrLf & ex.Message)
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim myDataBasePath As String = "C:\Users\user\Source\Workspaces\......\SOF003\Data.accdb" 'Here you put the full name of the database file (including path)
'The next line is for Access 2003 .mdb files
'Dim CadenaConection As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", myDataBasePath)
Dim CadenaConection As String = String.Format("Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0}", myDataBasePath)
AccessConection = New OleDbConnection(CadenaConection)
AccessConection.open()
End Sub
End Class
btSave is the command button.
Customs is the table's name.
CustomName and Address are two fields.
txName and txAddress are two TextBox Control.
Obviously you should be careful with the data types (here I use only strings), validation, etc, etc... But, this is a starting point. If you search, you'll find another ways, more elaborated.

Visual Basic Form. How to let users save text file where they want

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Dim CurrentDir As String = Environment.CurrentDirectory
Dim OutputFile2 As String = IO.Path.Combine(CurrentDir, "input.txt")
IO.File.WriteAllLines(OutputFile2, Result1.Lines)
End Sub
Right now, I have coding that saves a text file in the current directory. However, I want to have a browse button for users so that they can pick where this text file is saved. How do I proceed this?
I was trying it by my self and I'm having a trouble with using save file dialog. If you can teach me how to use a save file dialog or anyway to write save browse button, I would very appreciate it!
The documentation for the SaveFileDialog object contains an example.
Here is a tutorial on how to implement SaveFileDialog using Toolbox in Visual Studio like you mentioned. The code sample is in C# but it can be easily converted to VB.
Link: www.dotnetperls.com/savefiledialog
Private Sub button1_Click(sender As Object, e As EventArgs)
' When user clicks button, show the dialog.
saveFileDialog1.ShowDialog()
End Sub
Private Sub saveFileDialog1_FileOk(sender As Object, e As CancelEventArgs)
' Get file name.
Dim name As String = saveFileDialog1.FileName
' Write to the file name selected.
' ... You can write the text from a TextBox instead of a string literal.
File.WriteAllText(name, "test")
End Sub

VB 2010 mkdir read only

Hi i cant seem to get mkdir to create a folder which isnt read only, this is causing alot of problems in my code because i am unable to write files to the directory i have created. thanks for any help. this is my code below:
Else
MessageBox.Show("Please set a Root Path for your ****")
RootFBD.ShowDialog()
TextBox1.Text = RootFBD.SelectedPath
My.Computer.FileSystem.CreateDirectory("C:\****-Tools\config\root.txt")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f2 As New FileIOPermission(FileIOPermissionAccess.Read, TextBox1.Text)
f2.AddPathList(FileIOPermissionAccess.Write Or FileIOPermissionAccess.Read, TextBox1.Text)
Dim rootSave As System.IO.StreamWriter
rootSave = My.Computer.FileSystem.OpenTextFileWriter("C:\****-Tools\config\root.txt", True)
rootSave.WriteLine(TextBox1.Text)
Me.Hide()
MainTool.Show()
End Sub
End Class
Thanks again josh
You're misunderstanding the problem; this isn't a permission issue.
Rather, you're leaving the file open, which prevents other processes from writing to ir.
You just need to Close() your StreamWriter.
Or, you can just call File.AppendText, which will avoid the issue.
You are creating the directory with the file name. Try this:
My.Computer.FileSystem.CreateDirectory("C:\****-Tools\config")