Hi mukesh1,
Check this example. Now please take its reference and correct your code. There is no need to add N.
SQL
CREATE TABLE Languages(
[Language] VARCHAR(30) NOT NULL PRIMARY KEY,
Content NVARCHAR(200) NOT NULL
)
Entity Model
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Language" HeaderText="Language" />
<asp:BoundField DataField="Content" HeaderText="Content" />
</Columns>
</asp:GridView>
<br />
<asp:Button Text="Save" runat="server" OnClick="Save" />
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Language"), new DataColumn("Content") });
dt.Rows.Add("English", "World is beautiful.");
dt.Rows.Add("Hindi", "दुनिया सुंदर है।");
dt.Rows.Add("Marathi", "जग सुंदर आहे.");
dt.Rows.Add("Gujarati", "વિશ્વ સુંદર છે.");
dt.Rows.Add("Urdu", "دنیا خوبصورت ہے.");
dt.Rows.Add("Persian", "جهانی زیبا است.");
dt.Rows.Add("Arabic", "العالم هو جميل.");
dt.Rows.Add("Tamil", "உலக அழகாக இருக்கிறது.");
dt.Rows.Add("Telugu", "ప్రపంచ అందమైన ఉంది.");
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Save(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
foreach (GridViewRow row in GridView1.Rows)
{
using (TestEntities1 entities = new TestEntities1())
{
Language language = new Language()
{
Language1 = row.Cells[0].Text,
Content = row.Cells[1].Text
};
entities.AddToLanguages(language);
entities.SaveChanges();
}
}
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(1) {New DataColumn("Language"), New DataColumn("Content")})
dt.Rows.Add("English", "World is beautiful.")
dt.Rows.Add("Hindi", "दुनिया सुंदर है।")
dt.Rows.Add("Marathi", "जग सुंदर आहे.")
dt.Rows.Add("Gujarati", "વિશ્વ સુંદર છે.")
dt.Rows.Add("Urdu", "دنیا خوبصورت ہے.")
dt.Rows.Add("Persian", "جهانی زیبا است.")
dt.Rows.Add("Arabic", "العالم هو جميل.")
dt.Rows.Add("Tamil", "உலக அழகாக இருக்கிறது.")
dt.Rows.Add("Telugu", "ప్రపంచ అందమైన ఉంది.")
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub Save(sender As Object, e As EventArgs)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
For Each row As GridViewRow In GridView1.Rows
Using entities As TestEntities1 = New TestEntities1()
Dim language As Language = New Language() With {.Language1 = row.Cells(0).Text, .Content = row.Cells(1).Text}
entities.AddToLanguages(language)
entities.SaveChanges()
End Using
Next
End Using
End Sub
Screenshot
WebPage
After Insert Database