views:

91

answers:

2

I want to add a text field to a web page that lets users add space delimited tags. much like del.icio.us.

I am more interested in how I get them off the page and into the database using VB.NET and SQL.

Can anyone point me at any articles or code snippets on how I can achieve this using vb.net and sql 2005?

+1  A: 

You are going to need several techniques here and without knowing how much you already know it could be difficult (see my comment).

  1. You need to look at splitting up your delimited string from the TextBox.Text property (use String.Split(" ") to get an array of strings which represent your tags.

  2. You need a reference to the page that is being tagged (URL or another unique ID depends upon your scenario).

  3. Add both to your database, there are so many ways to do this. Look at System.Data.SqlClient namespace for SQL Server. Also lookup using datasets within Visual Studio as this may be quicker and easier for you.

You really need to include more info in you question. You might want to edit it and add more detail on what you already know and what aspects you need help with. The community cannot write your code for you but with properly structured questions we will get you the solutions to any problems you encounter.

Good luck!

Charlie
A: 

Here is an oversimplifed example. I am using c# but converting it to vb must be trivial. You will need to dig into lots of more details.

Assuming that you are using webforms, you need a textbox on your page:

<asp:TextBox ID="txtTags" runat="server" />

Assuming that you have a submit button:

<asp:Button ID="btnSubmit" onclick="SaveTags" runat="server" Text="submit" />

You would have a SaveTags method that handles the click event:

protected void SaveTags(object sender, EventArgs e)
{
    string[] tags = txtTags.Text.Split(' ');

    SqlConnection connection = new SqlConnection("Your connection string");
    SqlCommand command = connection.CreateCommand("Insert Into Tags(tag) Values(@tag)");
    foreach (string tag in tags)
    {
        command.Parameters.Clear();
        command.Parameters.AddWithValue("@tag", tag);
        command.ExecuteNonQuery();
    }
    connection.Close();
}
Serhat Özgel