Hi RichardSa,
So you need to use TextInfo class ToTitleCase method.
HTML
<form id="form1" runat="server">
<asp:GridView ID="gvNotes2" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Notes" HeaderText="Notes" />
</Columns>
</asp:GridView>
<asp:Label ID="lblNotes" runat="server"></asp:Label>
<asp:TextBox ID="txtNotes" runat="server"></asp:TextBox><br />
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="OnInsert" />
</form>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Globalization;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Globalization
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = "SELECT Notes FROM Notes2";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlDataAdapter sda = new SqlDataAdapter(query, con))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
gvNotes2.DataSource = dt;
gvNotes2.DataBind();
}
}
}
}
protected void OnInsert(object sender, EventArgs e)
{
string notes = txtNotes.Text;
txtNotes.Text = "";
string query = "INSERT INTO Notes2 VALUES(@Notes)";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Parameters.AddWithValue("@Notes", CultureInfo.InvariantCulture.TextInfo.ToTitleCase(notes));
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
this.BindGrid();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim query As String = "SELECT Notes FROM Notes2"
Using con As SqlConnection = New SqlConnection(constr)
Using sda As SqlDataAdapter = New SqlDataAdapter(query, con)
Using dt As DataTable = New DataTable()
sda.Fill(dt)
gvNotes2.DataSource = dt
gvNotes2.DataBind()
End Using
End Using
End Using
End Sub
Protected Sub OnInsert(ByVal sender As Object, ByVal e As EventArgs)
Dim notes As String = txtNotes.Text
txtNotes.Text = ""
Dim query As String = "INSERT INTO Notes2 VALUES(@Notes)"
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand(query)
cmd.Parameters.AddWithValue("@Notes", CultureInfo.InvariantCulture.TextInfo.ToTitleCase(notes))
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
Me.BindGrid()
End Sub
Screenshot