Post and get data from database and show on page or form

Ricardo Sousa 76 Reputation points
2025-12-06T04:51:43.98+00:00

Hi there how i can post data into database using webrequest and using forms to do this Post and Get information

 Dim Username As String 
            Dim Password As String 
            Dim Email As String 
            Dim Pass_Code As String 

            Dim url As String = "http://hostname" ' Any Hostname or IP Address 
            Dim Port As String = 8000 ' Any Port as you want 
           
            Username.Post = TxtBox_Username.Text
            Password.Post = TextBox_Password.Text
            Email.Post    = TextBox_Email.Text        
            Pass_Code.Post = TextBox_Pass_Code.Text 
             
            Dim request As HttpWebRequest = CType(WebRequest.Create(url,Port)
            Dim response As HttpWebResponse = CType(request.GetResponse()

            Using Post As New StreamWriter(responseText.Post.ToEnd(Data)
               
            Label1.Text = " All Data saved in Database "

            End Using
            response.Close()
        End If

Developer technologies | VB
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-12-06T04:51:58.2233333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To post data into a database using forms in ASP.NET, you typically use the POST method to submit the form data to the server. Here's a general outline of how to do this:

    1. Create an HTML Form: Set up an HTML form that collects the data you want to send to the server. For example:
         <form method="post" action="/submit">
             <input type="text" name="username" placeholder="Username" />
             <input type="password" name="password" placeholder="Password" />
             <input type="email" name="email" placeholder="Email" />
             <input type="text" name="pass_code" placeholder="Pass Code" />
             <input type="submit" value="Submit" />
         </form>
      
    2. Handle the POST Request: In your server-side code (e.g., in a Razor page), check if the request is a POST request. If it is, retrieve the form values using Request.Form and insert them into the database:
         @if (IsPost)
         {
             var username = Request.Form["username"];
             var password = Request.Form["password"];
             var email = Request.Form["email"];
             var passCode = Request.Form["pass_code"];
         
             var db = Database.Open("YourDatabaseName");
             var insertCommand = "INSERT INTO Users (Username, Password, Email, Pass_Code) VALUES(@0, @1, @2, @3)";
             db.Execute(insertCommand, username, password, email, passCode);
             Response.Redirect("/success"); // Redirect after successful submission
         }
      
    3. Display Data: To retrieve and display data from the database, you can use a GET request. For example, you might have another page that queries the database and displays the information:
         var db = Database.Open("YourDatabaseName");
         var results = db.Query("SELECT * FROM Users");
         foreach (var row in results)
         {
             <p>@row.Username - @row.Email</p>
         }
      

    In your VB.NET code, you would need to adjust the syntax accordingly, but the principles remain the same: use POST for submitting data and GET for retrieving data. Make sure to handle the database connection and queries properly to avoid SQL injection by using parameterized queries as shown above.


    References:

    0 comments No comments

  2. Ricardo Sousa 76 Reputation points
    2025-12-06T04:53:51.98+00:00

    no im not using MVC i want to use framework 4 and above not MVC

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.