我正在使用C#和SQL服務器。我使用了頂級查詢,但它只給我數據表的最高結果。通過在文本框中輸入此值,我想要20-40或30-100行的結果。如何從數據表中獲取特定行的記錄?
CREATE TABLE [dbo].[newpatient] (
[id] INT IDENTITY (1, 1) NOT NULL,
[serialno] VARCHAR (MAX) NULL,
[patientname] VARCHAR (100) CONSTRAINT [DF__newpatien__patie__1273C1CD] DEFAULT ('') NULL,
[age] INT CONSTRAINT [DF__newpatient__age__1367E606] DEFAULT ((0)) NULL,
[address] VARCHAR (100) CONSTRAINT [DF__newpatien__addre__145C0A3F] DEFAULT ('') NULL,
[symptoms] VARCHAR (MAX) CONSTRAINT [DF__newpatien__sympt__15502E78] DEFAULT ('') NULL,
[medicine] VARCHAR (MAX) CONSTRAINT [DF__newpatien__medic__164452B1] DEFAULT ('') NULL,
[bookingdate] DATETIME NULL,
[alloteddate] DATETIME NULL,
[village] VARCHAR (MAX) CONSTRAINT [DF__newpatien__villa__173876EA] DEFAULT ('') NULL,
[thana] VARCHAR (MAX) CONSTRAINT [DF__newpatien__thana__182C9B23] DEFAULT ('') NULL,
[district] VARCHAR (MAX) CONSTRAINT [DF__newpatien__distr__1920BF5C] DEFAULT ('') NULL,
[state] VARCHAR (MAX) CONSTRAINT [DF__newpatien__state__1A14E395] DEFAULT ('') NULL,
[isvalid] BIT CONSTRAINT [DF__newpatien__isval__1B0907CE] DEFAULT ('') NULL,
CONSTRAINT [pk_id_newpatient] PRIMARY KEY CLUSTERED ([id] ASC)
);
try
{
SuperClass sc = new SuperClass();
Cursor = Cursors.WaitCursor;
timer1.Enabled = true;
rptPatients rpt = new rptPatients();// created report
SqlCommand MyCommand = new SqlCommand();
SqlDataAdapter myDA = new SqlDataAdapter();
DB_DOCTORDataSet myDS = new DB_DOCTORDataSet();//created dataset
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=DB_DOCTOR;Integrated Security=True;Asynchronous Processing=True");
MyCommand.Connection = con;
MyCommand.CommandText = "select top '" + textBox1.Text + "' * from NewPatient";
MyCommand.CommandType = CommandType.Text;
myDA.SelectCommand = MyCommand;
myDA.Fill(myDS, "NewPatient");
rpt.SetDataSource(myDS);
crystalReportViewer1.ReportSource = rpt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
請重新格式化您的代碼並使其可讀。 –
我想獲取像20-30或50-60等行記錄 –
@RahulSharma,你可以請顯示你的表結構? – Sohail