Hi. I have created two tables :Artist and Song .Artist table has fields Artistid and ArtistName and Song table has SongID, Lyrics,Description and Artistid as the secondary key.I have a web form to add new artist containing a textbox and submit button . The code is as below :

<head id="Head1" runat="server">
        <title></title>

    </head>
    <body>
        <form id="form1" method ="post"> 
        <div style="width: 960px; color: black; border: 2px solid black; padding: 5px; text-align:"center">
        <table>
        <tr> 
        <td> <label>Artist: </label>
       <input type="text" name ="textArtist" id ="txtartist"  value = "" /> 
        </td>
        </tr>
        <tr>
        <td> 
        <p align="center" > 
        <input type = "button" id= "btnArtist" value ="submit" /> 
        </p> 
        </td> 
        </tr>

         </table>
        </div>
        </form>
    </body>

My requirement is that I will enter some name in textbox and click on submit , the same name should be shown in artist table in the database .
I have also created a namespace using Mygenerations with the artist and song table . I have written the foll code but it does not show the data in database .it does not work properly . Please help.
The code behind file is as below :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NCI.EasyObjects ;
using TestSong ;

public partial class _Default : System.Web.UI.Page
{
    string strcon = "Company";

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    void btnartist_onclick(object sender, EventArgs e)
    {
        string s_artistname = textArtist.Value; 
        Artist oArtist = new Artist(strcon);
        oArtist.Where.ArtistName.Value = s_artistname;
        if (!oArtist.Query.Load())
        {
            oArtist.AddNew();
            oArtist.ArtistName = textArtist.Value;
            oArtist.Save();
        }
    }

}  

Also i am getting an error for the line that has textArtist.Value . the error is textArtist does not exist in current context. Please tell me where m going wrong .

textArtist does not exist in current context

If you want to use textArtist the input has to have runat="server"

I have also created a namespace using Mygenerations with the artist and song table

What did you do exactly?

I have added runat=server and used the id i. txtartist in the line txtartist.value. The error is not there but the data entered is not shown in database .

How are you inserting into the database? Do you use Entity Framework, do you write your own queries? What?

No , whatever data will be entered in textbox should be shown in database . I got this working . Now I have another issue . I have a textarea control for the lyrics , so whatever lyrics will be entered in the textarea , it should be displayed in the database . The textarea control is as below :

<tr> 
    <td> 
    <label>Lyrics:</label>
    <textarea name="lyrics" id ="txtLyrics" cols="30" rows="10">
    </textarea>  
    </td> 
    </tr> 

I want the code using Mygenerations functions .

I want the code using Mygenerations functions .

I have no idea what you mean by that.

I meant that my main requrement is that i need to enter song name in the description textbox and its lyrics in the textarea control , so these should be shown in the song table in my database . I have written the below code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NCI.EasyObjects;
using TestSong; 

public partial class AddSong : System.Web.UI.Page
{
    string strcon = "Songs";
    protected void Page_Load(object sender, EventArgs e)
    {
        BindArtistData(); 
    }

    protected void btnSubmitSong_Click(object sender, EventArgs e)
    {
        Songs oSong = new Songs(strcon);
        oSong.Where.Description.Value = txtDescription.Value;
        if (!oSong.Query.Load())
        {
            oSong.AddNew();
            oSong.s_Description = txtDescription.Value;
            oSong.Save();
            AddLyrics();
        }
    }
    private void BindArtistData()
    {
       Artist oArtist = new Artist(strcon);
       if (oArtist.Query.Load())
        {
            ddlArtist.DataTextField = "ArtistName";
            ddlArtist.DataValueField = "ArtistID";
            ddlArtist.DataSource = oArtist.DefaultView.Table;
            ddlArtist.DataBind();
            ddlArtist.SelectedIndex = 0;
        }
    }


    private void AddLyrics()
    {
        Songs oSong = new Songs(strcon);
        oSong.Where.Lyrics.Value = txtLyrics.Value;
        if (!oSong.Query.Load())
        {
            oSong.AddNew();
            oSong.s_Lyrics = txtLyrics.Value;
            oSong.Save();
        }  
    }

} 

I tried running the above code , it shows the song and the lyrics in the database but in different rows i.e suppose i enter the song name and its lyrics , then the song name appears in one row where the lyrics are blank and the lyrics in another row , i want the name and the lyrics should appear in same row as it is a single entry . Please help .

Instead of AddLyrics(), just use oSong.s_Lyrics = txtLyrics.Value;

protected void btnSubmitSong_Click(object sender, EventArgs e)
{
    Songs oSong = new Songs(strcon);
    oSong.Where.Description.Value = txtDescription.Value;
    if (!oSong.Query.Load())
    {
        oSong.AddNew();
        oSong.s_Description = txtDescription.Value;
        oSong.s_Lyrics = txtLyrics.Value;
        oSong.Save();
    }
}

I got it working now.. now I have a field ArtistID in another table and it is used as a secondary key in the song table , so along with song name and lyrics also the corresponding artist ID should be shown in database but it is nt shown . Also there is a slight change . I am supposed to use html text editor for the lyrics instead of textarea control . I need to know how to write code for the html text editor.

I have a dropdownlist that shows artist name in a page called Addsongs.aspx . Also there is textbox for song description and ajaz toolkit text editor for entering lyrics on this page. After all the above is entered , artistID for the corresponding artistname should be shown in database but it is not being shown .

I think i will have to use some onchange function but dont knw the code for it .Someone plz help so that i can get the artistid shown in the table .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.