使用vb.net在SQL Server中存储文本文件数据

编程入门 行业动态 更新时间:2024-10-27 13:31:59
本文介绍了使用vb在SQL Server中存储文本文件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图将数据(txt格式)存储在SQL Server数据库中,但是当我为它创建虚拟目录时,它仅在我的系统(数据库和代码所在的系统)上工作. 我正在vb中编写此代码,请检查是否有任何错误. 设计文件

I m trying to store my data(txt format)in SQL server database but when I created virtual directory for it, its working only on my sytem (on which my database and the code exist). I am writing this code in vb, please check for any error. Design file

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="readingtext.aspx.vb" Inherits="readingtext" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="www.w3/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <%--<b>Raw File Output</b><br />--%> <center> <asp:label id="LblMsg" runat="server" /> <br /> <asp:TextBox ID="txtbox1" runat="server" Text=""></asp:TextBox> <%--<p> <u><b>Data Of Text File</b></u><br /></p> <asp:label runat="server" id="lblNicerOutput" Font-Name="Verdana" />--%> <br /> <asp:Button ID="Btn1" Text="PostTosql" runat="server" /> </center> </div> </form> </body> </html>

代码文件:

code file:

Imports System.Data.SqlClient Imports System.Data.Sql Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Text Imports System.Configuration Imports System.Xml Imports System.Data Imports System.Drawing Imports System.IO Partial Class readingtext Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'If Not IsPostBack Then ' LblMsg.Text = String.Empty ' txtbox1.Text = String.Empty 'End If End Sub Protected Sub Btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn1.Click Try Dim objSRFile As StreamReader Dim strInput, arrStrInput() As String Dim intCurrPos As Integer Dim strName As String Dim Age As String Dim RollNo As String strName = String.Empty Age = String.Empty RollNo = String.Empty 'Dim intSalary As Integer 'DB vars Dim strSQL As String Dim strConnString As String = ConfigurationManager.ConnectionStrings("MyCon").ConnectionString() Dim Con As New SqlConnection(strConnString) Dim objCmd As SqlCommand File.OpenText(txtbox1.Text) objSRFile = File.OpenText(txtbox1.Text) ' objSRFile = File.OpenText("x:\path\to\file.txt") While objSRFile.Peek <> -1 strInput = objSRFile.ReadLine arrStrInput = Split(strInput, ",", , CompareMethod.Text) For intCurrPos = 0 To arrStrInput.Length - 1 Select Case intCurrPos Case 0 strName = arrStrInput(intCurrPos) Case 1 Age = arrStrInput(intCurrPos) Case 2 RollNo = arrStrInput(intCurrPos) End Select Next strSQL = "insert into InsertDataNew(Name,age,RollNo) values('" & strName & "', '" & Age & "', '" & RollNo & "')" objCmd = New SqlCommand(strSQL, Con) Con.Open() objCmd.ExecuteNonQuery() LblMsg.Text = "Data has Entered Successfully" Con.Close() End While objSRFile.Close() Catch ex As Exception Trace.Write(ex.Message) End Try 'File to string vars End Sub End Class

推荐答案

所有权限均已正确分配, 但它仍无法正常工作. All permissions are assigned properly , but it is not working yet.

将其部署到另一台计算机时是否有问题?我想你是说这是问题. 如果它在本地运行,请确保在目标部署环境中,Web服务器所运行的帐户在您的数据目录中具有读/写权限. 干杯. Do you have a problem when you deploy it to another machine? I think you''re saying this is the problem. If it works locally, make sure the account that the web server runs under has read/write permission in your data directory in the target deployment environment. Cheers.

更多推荐

使用vb.net在SQL Server中存储文本文件数据

本文发布于:2023-07-09 00:19:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082122.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本文件   数据   net   vb   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!