datagrid view is not showing data - asp.net

I try this code for showing some info from sql database. but I can not see the datas in gridview..How can I solve?? Also, I have no error.
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection("Server=CAN-PC; Database=SMS; UID=SA; PWD=delidana1963");
string sql = "";
sql = #"select Orginator,RecordDate, (select COUNT(TurkcellID) from SmsStore ";
// txttarih.Text = Calendar1.SelectedDate.ToString();
var tarih1 = String.Format("{0:yyyy-MM-dd hh:mm}", Calendar1.SelectedDate.Date);
var tarih2 = String.Format("{0:yyyy-MM-dd hh:mm}", Calendar2.SelectedDate.Date);
if (Calendar1.SelectedDate != null && Calendar2.SelectedDate != null)
sql += "where RecordDate between '" +tarih1 + "' and '" + tarih2 + "'";
else if (Calendar1.SelectedDate != null && Calendar2.SelectedDate == null)
sql += "where RecordDate between '" + tarih1 + "' and '" + DateTime.Now + "'";
sql += ") as toplammsj,";
sql += "(select COUNT(TurkcellID) from SmsStore where TurkcellID=1 ";
if (Calendar1.SelectedDate != null && Calendar2.SelectedDate != null)
sql += "and RecordDate between '" + tarih1 + "' and '" + tarih2+ "'";
else if (Calendar1.SelectedDate != null && Calendar2.SelectedDate == null)
sql += "and RecordDate between '" + tarih1 + "' and '" + DateTime.Now + "'";
sql += ") as giden,";
sql += " (select COUNT(TurkcellID) from SmsStore where TurkcellID=0 ";
if (Calendar1.SelectedDate != null && Calendar2.SelectedDate != null)
sql += "and RecordDate between '" + tarih1 + "' and '" + tarih2 + "'";
else if (Calendar1.SelectedDate != null && Calendar2.SelectedDate == null)
sql += "and RecordDate between '" + tarih1 + "' and '" + DateTime.Now + "'";
sql += ") as gitmeyen from SmsStore ";
if (Calendar1.SelectedDate != null && Calendar2.SelectedDate != null)
sql += "where RecordDate between '" + tarih1+ "' and '" + tarih2 + "'";
else if (Calendar1.SelectedDate != null && Calendar2.SelectedDate == null)
sql += "where RecordDate between '" + tarih1 + "' and '" + DateTime.Now + "'";
SqlDataAdapter adp = new SqlDataAdapter(sql, cnn);
DataTable dt = new DataTable();
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.DataMember = "dt";
}
please help me about this problem.
thanks for all.

Is this a WPF GridView or a Windows Forms DataGridView? The WPF GridView does not have a DataSource property or DataBind() method. And for a DataGridView, you do not need to use DataBind() or set the DataMember property if the DataSource is a DataTable, as you have done.
Also, for debugging purposes put a breakpoint after the line adp.Fill(dt). Put your cursor over dt and examine the properties to determine if Rows.Count is greater than 0. If your SQL is messed up, you might not be getting any data from the database in the first place.

Related

How to declare scalar variable?

I get this error:
System.Data.SqlClient.SqlException: 'Must declare the scalar variable "#refSlips".'
Code:
SqlConnection con = new SqlConnection(connectionString);
SqlCommand aaa = new SqlCommand("INSERT INTO ConsultationTB VALUES('" + consultationTb.Text + "','" + dateTb.Text + "','" + bodytempTb.Text + "','" + paccodeTb.Text + "', #refSlips ", con);
string RadButt = string.Empty;
if (ForAdmission.Checked)
{
RadButt = "For Admission";
}
else if (ForLabTest.Checked)
{
RadButt = "For Laboratory Test";
}
else if (BothRb.Checked)
{
RadButt = "Both";
}
else if (NotAppRb.Checked)
{
RadButt = "Not Applicable";
}
con.Open();
aaa.ExecuteNonQuery();
con.Close();
getCONNO();
ForAdmission.Checked = false;
ForLabTest.Checked = false;
BothRb.Checked = false;
NotAppRb.Checked = false;
[ + "', #refSlips)" , con);] the problem was the parenthesis after refslips.

ASP .NET Forms and Submit

I am new to ASP .Net Web Forms. Tried creating a Web Page going through Youtube Tutorials and now I'm stuck on this step where I have created a form with inputs and select using Bootstrap. Here is what my Frontend looks like which is in Default.aspx ---->
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="jumbotron">
<center class="form-group-lg">
<form method="post" action="btnShow_Click">
<label>Token Number</label>
<input type="text" name="txtCommand" id="txtCommand" class="text-center form-control" value="" runat="server" />
<div class="row form-group">
<div class="col-md-4">
<label>Room Number</label>
<select class="form-control" name="CounterID" id="CounterID" runat="server">
<option value="0">Select Room Number</option>
<option value="1">Room Number 01</option>
<option value="2">Room Number 02</option>
<option value="3">Room Number 03</option>
<option value="4">Room Number 04</option>
<option value="5">Room Number 05</option>
<option value="6">Room Number 06</option>
<option value="7">Room Number 07</option>
<option value="8">Room Number 08</option>
<option value="9">Room Number 09</option>
<option value="10">Room Number 10</option>
</select>
</div>
<div class="col-md-4">
<label>Department</label>
<select class="form-control" id="CounterName" name="CounterName" runat="server">
</select>
</div>
<div class="col-md-4">
<label>Terminal</label>
<input type="text" class="form-control" name="TerminalID" id="TerminalID" runat="server" value="000" />
</div>
</div>
<div class="row">
<div class="col-md-6">
<p>Waiting Patients: <span id="label2">100</span></p>
<!-- <input type="text" readonly name="" id="label2" class="form-control" runat="server" value=""/> -->
</div>
<div class="col-md-6">
<p>Total Patients: <span id="label1">100</span></p>
<!-- <input type="text" readonly name="label1" id="label1" class="form-control" runat="server" value=""/> -->
</div>
</div>
<div class="form-group" style="margin-top:15px;">
<asp:Button ID="btnShow" type="submit" runat="server" Text="Next" Width="56px"/>
</div>
</form>
</center>
</div>
</asp:Content>
and my Default.aspx.cs looks like --->>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace WebApplication2
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
string conn = ConfigurationManager.ConnectionStrings["GIMS_HIMS"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(conn);
string depart = "select DeptCode, DepartmentName from Que_Master_Department where Active = 1";
SqlDataAdapter sda = new SqlDataAdapter(depart, sqlconn);
sqlconn.Open();
DataTable dt = new DataTable();
sda.Fill(dt);
CounterName.DataSource = dt;
CounterName.DataTextField = "DepartmentName";
CounterName.DataValueField = "DepartmentName";
CounterName.DataBind();
sqlconn.Close();
btnShow.Click += btnShow_Click;
}
//Recall Button Commands Start Here
private void Recall_Click(object sender, EventArgs e)
{
CalcPatientRemain();
string conn = ConfigurationManager.ConnectionStrings["GIMS_HIMS"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(conn);
string query = " DELETE FROM Que_Delegation WHERE Token = '" + txtCommand.Value + "'";
SqlCommand scom = new SqlCommand(query, sqlconn);
sqlconn.Open();
scom.ExecuteNonQuery();
query = " INSERT INTO Que_Delegation (Token, TerminalID, CounterID, CounterName, Dispatch) VALUES ('" + txtCommand.Value + "','" + TerminalID + "','" + CounterID + "','" + CounterName + "','False')";
SqlCommand scom1 = new SqlCommand(query, sqlconn);
scom1.ExecuteNonQuery();
sqlconn.Close();
}
//Recall Button Commands Ended
//Next Button Commands Starts
protected void Next_Click(object Sender, EventArgs e)
{
GetToken();
CalcPatientRemain();
MainScreenDisplay();
}
public void GetToken()
{
try
{
string conn = ConfigurationManager.ConnectionStrings["GIMS_HIMS"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(conn);
String userqry = "SELECT TOP(1) Token, ID FROM Que_Management2 Where Department = '" + CounterName + "' AND Flag = 'False' ORDER BY ID ASC";
sqlconn.Open();
SqlCommand cmd = new SqlCommand(userqry, sqlconn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
while (dr.Read())
{
txtCommand.Value = dr[0].ToString();
}
}
else
{
txtCommand.Value = string.Empty;
}
dr.Close();
string query = "Update Que_Management2 SET Flag = 'True' WHERE Token = '" + txtCommand.Value + "'";
SqlCommand scom2 = new SqlCommand(query, sqlconn);
scom2.ExecuteNonQuery();
if (txtCommand.Value != "")
{
query = " DELETE FROM Que_Delegation";
SqlCommand scom3 = new SqlCommand(query, sqlconn);
scom3.ExecuteNonQuery();
query = " INSERT INTO Que_Delegation (Token, TerminalID, CounterID, CounterName, Dispatch) VALUES ('" + txtCommand.Value + "','" + TerminalID + "','" + CounterID + "','" + CounterName + "','False')";
SqlCommand scom4 = new SqlCommand(query, sqlconn);
scom4.ExecuteNonQuery();
}
sqlconn.Close();
}
catch (Exception ex)
{
string abc = ex.Message;
}
}
public void CalcPatientRemain()
{
try
{
string conn = ConfigurationManager.ConnectionStrings["GIMS_HIMS"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(conn);
sqlconn.Open();
DateTime Date1 = DateTime.Today;
DateTime Date2 = DateTime.Today.AddDays(1);
SqlDataReader dr;
SqlCommand cmd;
cmd = new SqlCommand("usp_GetPatientRemain", sqlconn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#Date1", SqlDbType.DateTime).Value = Date1;
cmd.Parameters.Add("#Date2", SqlDbType.DateTime).Value = Date2;
cmd.Parameters.Add("#Department", SqlDbType.NVarChar).Value = CounterName;
dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
while (dr.Read())
{
label2.Value = (dr[0].ToString());
}
}
dr.Close();
cmd = new SqlCommand("usp_GetPatientTotal", sqlconn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#Date1", SqlDbType.DateTime).Value = Date1;
cmd.Parameters.Add("#Date2", SqlDbType.DateTime).Value = Date2;
cmd.Parameters.Add("#Department", SqlDbType.NVarChar).Value = CounterName;
dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
while (dr.Read())
{
label1.Value = (dr[0].ToString());
}
}
dr.Close();
sqlconn.Close();
}
catch (Exception ex)
{
string abc = ex.Message;
}
}
public void MainScreenDisplay()
{
string conn = ConfigurationManager.ConnectionStrings["GIMS_HIMS"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(conn);
sqlconn.Open();
string Date = DateTime.Now.ToString("MM/dd/yyyy");
string query = "";
if (txtCommand.Value == "" || txtCommand.Value == null)
{
txtCommand.Value = "----";
}
if (CounterID.Value == "1")
{
query = "Update Que_MainScreenDelegate2 SET T1 = '" + txtCommand.Value + "', C1 = '" + CounterID + "', CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom5 = new SqlCommand(query, sqlconn);
scom5.ExecuteNonQuery();
}
else if (CounterID.Value == "2")
{
query = "Update Que_MainScreenDelegate2 SET T2 = '" + txtCommand.Value + "', C2 = '" + CounterID + "', CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom6 = new SqlCommand(query, sqlconn);
scom6.ExecuteNonQuery();
}
else if (CounterID.Value == "3")
{
query = "Update Que_MainScreenDelegate2 SET T3 = '" + txtCommand.Value + "', C3 = '" + CounterID + "', CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom7 = new SqlCommand(query, sqlconn);
scom7.ExecuteNonQuery();
}
else if (CounterID.Value == "4")
{
query = "Update Que_MainScreenDelegate2 SET T4 = '" + txtCommand.Value + "', C4 = '" + CounterID + "', CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom8 = new SqlCommand(query, sqlconn);
scom8.ExecuteNonQuery();
}
else if (CounterID.Value == "5")
{
query = "Update Que_MainScreenDelegate2 SET T5 = '" + txtCommand.Value + "', C5 = '" + CounterID + "' , CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom9 = new SqlCommand(query, sqlconn);
scom9.ExecuteNonQuery();
}
else if (CounterID.Value == "6")
{
query = "Update Que_MainScreenDelegate2 SET T6 = '" + txtCommand.Value + "', C6 = '" + CounterID + "' , CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom10 = new SqlCommand(query, sqlconn);
scom10.ExecuteNonQuery();
}
else if (CounterID.Value == "7")
{
query = "Update Que_MainScreenDelegate2 SET T7 = '" + txtCommand.Value + "', C7 = '" + CounterID + "', CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom11 = new SqlCommand(query, sqlconn);
scom11.ExecuteNonQuery();
}
else if (CounterID.Value == "8")
{
query = "Update Que_MainScreenDelegate2 SET T8 = '" + txtCommand.Value + "', C8 = '" + CounterID + "', CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom12 = new SqlCommand(query, sqlconn);
scom12.ExecuteNonQuery();
}
else if (CounterID.Value == "9")
{
query = "Update Que_MainScreenDelegate2 SET T9 = '" + txtCommand.Value + "', C9 = '" + CounterID + "', CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom13 = new SqlCommand(query, sqlconn);
scom13.ExecuteNonQuery();
}
else if (CounterID.Value == "10")
{
query = "Update Que_MainScreenDelegate2 SET T10 = '" + txtCommand.Value + "', C10 = '" + CounterID + "', CMain = '" + CounterID + "', TMain = '" + txtCommand.Value + "', Sound = 'YES' WHERE Date = '" + Date + "'";
SqlCommand scom14 = new SqlCommand(query, sqlconn);
scom14.ExecuteNonQuery();
}
}
//Next Button Commands Ended
protected void btnShow_Click(object Sender, EventArgs e)
{
// Page.ClientScript.RegisterStartupScript(
//Page.GetType(),
//"MessageBox",
//"<script language='javascript'>alert('Hello');</script>"
//);
GetToken();
CalcPatientRemain();
MainScreenDisplay();
}
}
}
The problem I'm facing is its doing nothing. No changes are visible and the database also shows no updates. The button works when I trigger OnClick event on it as show in the commented function where I was showing a message on button click but same when I try my functions its not working. Can someone please help what I'm doing wrong.
Dump this tutorial immediately. It teaches you an outdated framework (WebForms is not maintained anymore and won't run on .NET 5), and worse, it has giant SQL injection vulnerabilities (despite using parameterized queries - sometimes). Seriously, tutorials like this should be pulled.
If you want to create a .NET web application in 2021, use ASP.NET Core MVC or Razor Pages.
As for your error, you don't bind the Recall_Click handler to any button.

Validate last 2 letters into dynamic query

Im doing a Dynamic Query into ASP.NET using SQL Server 2016.
Basically i have some checkbox and textbox:
<asp:CheckBox ID="chk_Precio" runat="server" OnCheckedChanged="chk_Precio_CheckedChanged" AutoPostBack="true" />
<asp:TextBox ID="txtPrecio" runat="server" CssClass="enjoy-css" style="margin-bottom: 0"></asp:TextBox>
<asp:CheckBox ID="chk_Modelo" runat="server" AutoPostBack="true" OnCheckedChanged="chk_Modelo_CheckedChanged" />
<asp:TextBox ID="txtModelo" runat="server" CssClass="enjoy-css" style="margin-bottom: 0"></asp:TextBox>
<asp:Button ID="btnBuscar" CssClass="button" runat="server" Text="Buscar" OnClick="btnBuscar_Click" />
These are validated in chk_Modelo_CheckedChanged.
Inside btnBuscar_Click i have:
protected void btnBuscar_Click(object sender, EventArgs e)
{
string query = "SELECT p.OrderId AS Orden, p.OrderDate as Fechadecompra, '$'+Convert(varchar,convert(money,p.Amount),1) as PrecioCompra, c.ModelCar as Modelo, b.Description_Brand as Marca, c.Color, t.Description_Transmision as Transmision, s.StatusName AS Estado FROM PurchaseOrder AS p INNER JOIN Cars AS c ON p.IdCar = c.IdCar INNER JOIN Brand AS b ON c.IdBrand = b.IdBrand INNER JOIN TransmisionType AS t ON c.IdTransmision = t.IdTransmision INNER JOIN Status AS s on c.IdStatus = s.IdStatus where ";
string varprecio = txtPrecio.Text;
string varModelo = txtModelo.Text;
try
{
if (varprecio != "")
{
query += "(p.Amount = '"+varprecio +"') or";
}
else if(varModelo != "")
{
query += "(c.ModelCar = '"+varModelo +"') or";
}
string str = "Data Source=DESKTOP-77G5EDB\\SQLEXPRESS;Initial Catalog=TallerDB;Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(str);
SqlCommand cmd = new SqlCommand(query, sqlConnection);
sqlConnection.Open();
SqlDataReader dr = cmd.ExecuteReader();
dtgv_Compras.DataSource = dr;
dtgv_Compras.DataBind();
}
catch (Exception ex)
{
Response.Write("<script>alert('ERROR: " + ex.Message + "')</script>");
}
}
My question is:
How can i validate if my query ends with: OR, delete these OR and my query finish correctly.
query += "(p.Amount = '"+varprecio +"') or";
F.E.:
SELECT p.OrderId AS Orden, p.OrderDate as Fechadecompra, '$'+Convert(varchar,convert(money,p.Amount),1) as PrecioCompra, c.ModelCar as Modelo, b.Description_Brand as Marca, c.Color, t.Description_Transmision as Transmision, s.StatusName AS Estado
FROM PurchaseOrder AS p
INNER JOIN Cars AS c ON p.IdCar = c.IdCar
INNER JOIN Brand AS b ON c.IdBrand = b.IdBrand
INNER JOIN TransmisionType AS t ON c.IdTransmision = t.IdTransmision
INNER JOIN Status AS s on c.IdStatus = s.IdStatus where (p.Amount = '5000')
Thanks in advance
I made some changes in your button click.
protected void btnBuscar_Click(object sender, EventArgs e)
{
string query = "SELECT p.OrderId AS Orden, p.OrderDate as Fechadecompra, '$'+Convert(varchar,convert(money,p.Amount),1) as PrecioCompra, c.ModelCar as Modelo, b.Description_Brand as Marca, c.Color, t.Description_Transmision as Transmision, s.StatusName AS Estado FROM PurchaseOrder AS p INNER JOIN Cars AS c ON p.IdCar = c.IdCar INNER JOIN Brand AS b ON c.IdBrand = b.IdBrand INNER JOIN TransmisionType AS t ON c.IdTransmision = t.IdTransmision INNER JOIN Status AS s on c.IdStatus = s.IdStatus ";
string varprecio = txtPrecio.Text;
string varModelo = txtModelo.Text;
try
{
if (varprecio != "" || varModelo != "")
query += "where ";
if (varprecio != "")
{
query += "(p.Amount = '" + varprecio + "')";
if (varModelo != "")
query += " or ";
}
if (varModelo != "")
{
query += "(c.ModelCar = '" + varModelo + "')";
}
string str = "Data Source=DESKTOP-77G5EDB\\SQLEXPRESS;Initial Catalog=TallerDB;Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(str);
SqlCommand cmd = new SqlCommand(query, sqlConnection);
sqlConnection.Open();
SqlDataReader dr = cmd.ExecuteReader();
dtgv_Compras.DataSource = dr;
dtgv_Compras.DataBind();
}
catch (Exception ex)
{
Response.Write("<script>alert('ERROR: " + ex.Message + "')</script>");
}
}
Hope this will work for you. Please let me know if you will still facing issue.
Try this so you don't have to check whether they are blank or not
query += "('" + varprecio +"' = '''' or p.Amount = '" + varprecio +"') AND"
query += "('" + varModelo +"' = '''' or c.ModelCar = '"+varModelo +"')";
Which will give you
WHERE ('' = '' OR p.amount = '') AND ('' = '' or c.ModelCar = '')
or
WHERE ('abc' = '' OR p.amount = 'abc') AND ('xyz' = '' or c.ModelCar = 'xyz')
so if they are blank they are ignored on the SQL side.
I was trying in my work with oracle and i found this:
SELECT SUBSTR('select * from table where condicion = value or', 1, (LENGTH('select * from table where condicion = value or') - 2))
FROM dual where (SUBSTR ('select * from table where condicion = value or', -2,LENGTH('select * from table where condicion = value or')) = 'or');
Query:
select * from table where condicion = value or
Result:
I'll convert later to transact-sql in case someone uses the code into oracle.

Get checkbx values selected from database

I have users form in which they can select some values from checkbox list & values selected in that stores in database in li form. Now I want when users wants to update their form they should be able to see the values checked they have selected earlier.
here is my code.
Insert Form
Private Sub PopulateServices()
Using conn As New MySqlConnection()
conn.ConnectionString = ConfigurationManager _
.ConnectionStrings("conio").ConnectionString()
Using cmd As New MySqlCommand()
cmd.CommandText = "select * from services"
cmd.Connection = conn
conn.Open()
Using sdr As MySqlDataReader = cmd.ExecuteReader()
While sdr.Read()
Dim item As New ListItem()
item.Text = sdr("serviceName").ToString()
item.Value = sdr("serviceName").ToString()
'item.Selected = Convert.ToBoolean(sdr("IsSelected"))
servicesList.Items.Add(item)
End While
End Using
conn.Close()
End Using
End Using
End Sub
Dim selectedServices As String = String.Empty
For Each chk As ListItem In servicesList.Items
If chk.Selected = True Then
selectedServices &= "<li>" + chk.Text + "</li>"
End If
Next
Try
Dim str1 As String = "INSERT INTO hospitals (`hospitalID`,`username`, `password`) values ('" + ID + "', '"selectedServices.ToString + "', '" + mobileNumber + "', '" + membersAutoPassword.Text + "')"
Dim str2 As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = str1
command.Connection = con
adapter.SelectCommand = command
con.Open()
str2 = command.ExecuteReader
con.Close()
Response.Redirect("business-added.aspx")
Catch ex As Exception
Response.Write(ex)
End Try
On User Profile page after login they should be able to see what options they have selected. Hence there is a option for users to update their details again
UPDATED
User Profile Page
Private Sub list_business_hospital_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Try
Dim str As String = "SELECT * FROM hospitals WHERE username='" + Server.HtmlEncode(Request.Cookies("chkusername").Value) + "';"
con.Open()
Dim cmd As New MySqlCommand(str, con)
Dim da As New MySqlDataAdapter(cmd)
Dim dt As New DataTable
Dim lblservice As New Label
For Each chk As ListItem In servicesList.Items
If chk.Selected = True Then
lblservice.Text = String.Concat(lblservice.Text + ",", chk.Value)
End If
Next
da.Fill(dt)
con.Close()
TextId.Text = dt.Rows(0)("hospitalID").ToString
Catch ex As Exception
Response.Write(ex)
End Try
Private Sub PopulateServices()
Using conn As New MySqlConnection()
conn.ConnectionString = ConfigurationManager _
.ConnectionStrings("conio").ConnectionString()
Using cmd As New MySqlCommand()
cmd.CommandText = "select * from services"
cmd.Connection = conn
conn.Open()
Using sdr As MySqlDataReader = cmd.ExecuteReader()
While sdr.Read()
Dim item As New ListItem()
item.Text = sdr("serviceName").ToString()
item.Value = sdr("serviceName").ToString()
'item.Selected = Convert.ToBoolean(sdr("IsSelected"))
servicesList.Items.Add(item)
End While
End Using
conn.Close()
End Using
End Using
End Sub
Private Sub updateInfo_Click(sender As Object, e As EventArgs) Handles updateInfo.Click
Try
Dim con As New MySqlConnection
Dim query As New MySqlCommand
con.ConnectionString = ConfigurationManager _
.ConnectionStrings("conio").ConnectionString()
query.Connection = con
con.Open()
Dim selectedServices As String = String.Empty
For Each chk As ListItem In servicesList.Items
If selectedServices.Contains("<li>" & chk.Text & "</li>") Then
'display item as selected
chk.Selected = True
End If
Next
query.CommandText = "UPDATE hospitals SET name = '" + businessName.Text + "', contactPerson = '" + contactPerson.Text + "', websiteName = '" + websiteName.Text + "', email = '" + emailName.Text + "', phone1 = '" + phone1.Text + "', phone2 = '" + phone2.Text + "', mobileNumber = '" + mobile.Text + "', buildingName = '" + buildingName.Text + "', streetName = '" + address.Text + "', landmark = '" + landmark.Text + "', areaName = '" + areaName.Text + "', city = '" + suburb.Text + "', state = '" + state.Text + "', zipCode = '" + zip.Text + "', overview = '" + overview.Text + "', registration = '" + regNo.Text + "', establishment = '" + foundation.Text + "', founder = '" + founderName.Text + "', generalBed = '" + GeneralBeds.Text + "', icuBed = '" + ICU.Text + "', consultancyFees = '" + consultinfees.Text + "', mondayFrom = '" + mondayFrom.Text + "', mondayTo = '" + mondayTo.Text + "', tuesdayFrom = '" + tuesdayFrom.Text + "', tuesdayTo = '" + tuesdayTo.Text + "', wednesdayFrom = '" + wedFrom.Text + "', wednesdayTo = '" + wedTo.Text + "', thursdayFrom = '" + thursdayFrom.Text + "', thursdayTo = '" + thursdayTo.Text + "', fridayFrom = '" + fridayFrom.Text + "', fridayTo = '" + fridayTo.Text + "', saturdayFrom = '" + saturdayFrom.Text + "', saturdayTo = '" + saturdayTo.Text + "', sundayFrom = '" + sundayFrom.Text + "', sundayTo = '" + sundayTo.Text + "', visitFrom = '" + visitFrom.Text + "', visitTo = '" + visitTo.Text + "', bestKnownFor = '" + bestknowFor.Text + "' WHERE hospitalID = '" + TextId.Text + "'"
query.ExecuteNonQuery()
con.Close()
Response.Write("<script language='javascript'>alert('Information updated successfully.');</script>")
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
Please check below,
'Here I assume that, you will call PopulateServices to populate servicesList checkbox list
PopulateServices()
'You didn't mention fieldName, so I assume that field in database is :
'savedServices - This will be li tags like, <li>item 1</li><li>item 2</li>
'Now loop through all items within checkbox list
For Each chk As ListItem In servicesList.Items
'You need to check whether this item saved in database or not?
'If item already saved in database, display as selected
If savedServices.Contains("<li>" & chk.Text & "</li>") Then
'display item as selected
chk.selected = true
End If
Next

Syntax error (missing operator) in query expression for date in asp.net

the date in excel is of the date time format and the selected date is also date time format but wots the problem
OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT [ProjectId],[ProjectName],[ManagerID],[ManagerName],[AllocationStartDate],[AllocationEndDate],[horizontalshortname] FROM [" + getExcelSheetName + #"] where [horizontalshortname]="+ "'" + TextBox_Horizontal.Text + "'"
+ " AND [Isonsite]=" + "'" + DropDownList_Location.SelectedItem.Text + "'"
+ " AND [AllocationStartDate]>="+Calendar1.SelectedDate
+ " AND [AllocationEndDate]<="+Calendar2.SelectedDate
, conn);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
//if (ds.Tables[0] != null )
if (ds1.Tables[0].Rows.Count > 0)
{
GridView_Utilization_Search.Visible = true;
GridView_Utilization_Search.DataSource = ds1.Tables[0];
GridView_Utilization_Search.DataBind();
}
else
{
GridView_Utilization_Search.Visible = false;
}

Resources