Hey micah,
I checked the code is working, So please refer below code.
HTML
<div>
name:
<asp:TextBox runat="server" ID="txtName" /><br />
country:
<asp:TextBox runat="server" ID="txtCountry" />
<asp:LinkButton ID="btnsubmit" runat="server" CssClass="btn btn-info btn-circle"
Height="50px" Width="120px" Font-Bold="True" OnClick="btnsubmit_Click">Save Record</asp:LinkButton>
<asp:Button ID="btnReset" runat="server" CssClass="btn btn-default btn-circle" Text="Refresh"
Height="50px" Width="100px" Font-Bold="True" OnClick="btnReset_Click" />
<asp:Label ID="Label6" runat="server"></asp:Label>
<div class=" text-right" style="">
<asp:Panel ID="Panel2" runat="server" Font-Size="Large" Visible="false">
<asp:Label ID="lblMessage2" runat="server" Text="" CssClass="alert alert-danger alert-dismissable"></asp:Label>
</asp:Panel>
</div>
</div>
Namespaces
C#
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
Code
C#
protected void btnsubmit_Click(object sender, EventArgs e)
{
int inserted = 0;
string str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = str;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
cmd.CommandText = "INSERT INTO Customers (Name,Country) VALUES(@Name,@Country)";
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Country", txtCountry.Text);
con.Open();
inserted = cmd.ExecuteNonQuery();
con.Close();
Panel2.Visible = true;
string message = string.Empty;
{
lblMessage2.Visible = true;
lblMessage2.Text = "Data Submitted Successfully";
}
}
}
}
protected void btnReset_Click(object sender, EventArgs e)
{
txtName.Text = "";
txtCountry.Text = "";
}
Screenshot
