kankon says:
using
(SqlDataAdapter da =
new
SqlDataAdapter(
"SELECT * FROM Table_vacation WHERE namevacation = 'اجازة دورية' OR namevacation = 'اجازة دورية للاشرافيين' AND datestart >= DATEADD(MONTH, -3, GETDATE()) ORDER BY [id] DESC"
, con))
Add prefix N before the parameter value.
using (SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Table_vacation WHERE namevacation = N'اجازة دورية' OR namevacation = N'اجازة دورية للاشرافيين' AND datestart >= DATEADD(MONTH, -3, GETDATE()) ORDER BY [id] DESC", con))
Its better use parameterized query.
Check the below example.
HTML
<asp:GridView runat="server" ID="gvFiles" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="namevacation" HeaderText="Vacation Name" />
</Columns>
</asp:GridView>
Namespaces
C#
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGridView();
}
}
private void BindGridView()
{
string str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(str))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT * FROM Table_vacation WHERE namevacation = @Con1 OR namevacation = @Con2 ORDER BY [ID] DESC";
cmd.Parameters.AddWithValue("@Con1", "اجازة دورية");
cmd.Parameters.AddWithValue("@Con2", "اجازة دورية للاشرافيين");
cmd.Connection = con;
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
da.Fill(dt);
this.gvFiles.DataSource = dt;
this.gvFiles.DataBind();
}
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGridView()
End If
End Sub
Private Sub BindGridView()
Dim str As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(str)
Using cmd As SqlCommand = New SqlCommand()
cmd.CommandText = "SELECT * FROM Language WHERE Content = @Con1 OR Content = @Con2 ORDER BY [ID] DESC"
cmd.Parameters.AddWithValue("@Con1", "اجازة دورية")
cmd.Parameters.AddWithValue("@Con2", "اجازة دورية للاشرافيين")
cmd.Connection = con
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dt As DataTable = New DataTable()
da.Fill(dt)
Me.gvFiles.DataSource = dt
Me.gvFiles.DataBind()
End Using
End Using
End Using
End Using
End Sub