收录日期:2018/07/17 00:06:05 时间:2016/05/18 06:55:04 标签:C#
public void GetConfig(out string audiodevice,out string videodevice,
                       out string encoderrate,out string defaultpath,
                       out bool saveflag,out string filename,out int filesize,
                       out string localip,out int port)
{
try
{
string connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=log.mdb";
OleDbConnection conn = new OleDbConnection(connection);
OleDbDataAdapter adapter = new OleDbDataAdapter();
conn.Open();
//adapter.SelectCommand = new OleDbCommand(query, conn);
adapter.SelectCommand = new OleDbCommand("select @audiodevice=audiodevice,"+
"@videodevice=videodevice, @encoderrate=encoderrate,"+
"@defaultpath=defaultpath,@saveflag=saveflag,"+
"@filename=filename,@filesize=filesize,@localip=localip,"+
"@port=port where PKId=1" ,conn);

adapter.SelectCommand.Parameters.Add(new OleDbParameter("@audiodevice", OleDbType.Char,50));
adapter.SelectCommand.Parameters.Add(new OleDbParameter("@videodevice", OleDbType.Char,50));
adapter.SelectCommand.Parameters.Add(new OleDbParameter("@encoderrate", OleDbType.Char,250));
adapter.SelectCommand.Parameters.Add(new OleDbParameter("@defaultpath", OleDbType.Char,250));
adapter.SelectCommand.Parameters.Add(new OleDbParameter("@saveflag", OleDbType.Boolean));
adapter.SelectCommand.Parameters.Add(new OleDbParameter("@filename", OleDbType.Char,50));
adapter.SelectCommand.Parameters.Add(new OleDbParameter("@filesize", OleDbType.Integer));
adapter.SelectCommand.Parameters.Add(new OleDbParameter("@localip", OleDbType.Char,15));
adapter.SelectCommand.Parameters.Add(new OleDbParameter("@port", OleDbType.Integer));

audiodevice=adapter.SelectCommand.Parameters["@audiodevice"].Value.ToString();
videodevice=adapter.SelectCommand.Parameters["@videodevice"].Value.ToString();
encoderrate=adapter.SelectCommand.Parameters["@encoderrate"].Value.ToString();
defaultpath=adapter.SelectCommand.Parameters["@defaultpath"].Value.ToString();
saveflag=Convert.ToBoolean(adapter.SelectCommand.Parameters["@saveflag"].Value);
filename=adapter.SelectCommand.Parameters["@filename"].Value.ToString();
filesize=Convert.ToInt16(adapter.SelectCommand.Parameters["@filesize"].Value);
localip=adapter.SelectCommand.Parameters["@localip"].Value.ToString();
port=Convert.ToInt16(adapter.SelectCommand.Parameters["@port"].Value);

DataSet ds=new DataSet();
adapter.Fill(ds);

conn.Close();
}
catch(Exception ee)
{
string sError;
sError= ee.Message;
audiodevice="default";
videodevice="default";
encoderrate="386";
defaultpath="c:\\";
saveflag=false;
filename="222";
filesize=1024;
localip="192.168.0.241";
port=8080;
}

}
你的问题呢?
执行不了,出错,说没有实例
当然不对,你是要传进参数进行查询,但是还没给参数赋值,就用参数来赋值,如下语句都应反过来:
audiodevice=adapter.SelectCommand.Parameters["@audiodevice"].Value.ToString();
videodevice=adapter.SelectCommand.Parameters["@videodevice"].Value.ToString();
encoderrate=adapter.SelectCommand.Parameters["@encoderrate"].Value.ToString();
defaultpath=adapter.SelectCommand.Parameters["@defaultpath"].Value.ToString();
saveflag=Convert.ToBoolean(adapter.SelectCommand.Parameters["@saveflag"].Value);
filename=adapter.SelectCommand.Parameters["@filename"].Value.ToString();
filesize=Convert.ToInt16(adapter.SelectCommand.Parameters["@filesize"].Value);
localip=adapter.SelectCommand.Parameters["@localip"].Value.ToString();
port=Convert.ToInt16(adapter.SelectCommand.Parameters["@port"].Value);
up
:).那接下来还有什么问题呢?